diff options
| author | Xu Cheng | 2015-09-08 15:57:48 +0800 |
|---|---|---|
| committer | Xu Cheng | 2015-09-09 12:21:24 +0800 |
| commit | 2b835551d7f123df111924f3be2ca8465cc9f414 (patch) | |
| tree | 699d9684f2e3f09ebeab695cb35dd7143cba025e /Library/Homebrew | |
| parent | c8efb058267b3500ee5c40ebf58de3feea8841a5 (diff) | |
| download | brew-2b835551d7f123df111924f3be2ca8465cc9f414.tar.bz2 | |
info: improve github_info
* use Homebrew.git_origin
* Handle the case git is unavailable or `.git` doesn't exist
* Handle the case origin isn't github repo
Diffstat (limited to 'Library/Homebrew')
| -rw-r--r-- | Library/Homebrew/cmd/info.rb | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/Library/Homebrew/cmd/info.rb b/Library/Homebrew/cmd/info.rb index 21c04ed46..a2b491e05 100644 --- a/Library/Homebrew/cmd/info.rb +++ b/Library/Homebrew/cmd/info.rb @@ -58,23 +58,31 @@ module Homebrew puts Utils::JSON.dump(json) end - def github_fork - if (HOMEBREW_REPOSITORY/".git").directory? - if `git remote -v` =~ %r{origin\s+(https?://|git(?:@|://))github.com[:/](.+)/homebrew} - $2 - end + def github_remote_path(remote, path) + if remote =~ %r{^(?:https?://|git(?:@|://))github\.com[:/](.+)/(.+?)(?:\.git)?$} + "https://github.com/#{$1}/#{$2}/blob/master/#{path}" + else + "#{remote}/#{path}" end end def github_info(f) if f.tap? user, repo = f.tap.split("/", 2) - path = f.path.relative_path_from(HOMEBREW_LIBRARY.join("Taps", f.tap)) - "https://github.com/#{user}/#{repo}/blob/master/#{path}" + tap = Tap.new user, repo.gsub(/^homebrew-/, "") + if remote = tap.remote + path = f.path.relative_path_from(tap.path) + github_remote_path(remote, path) + else + f.path + end elsif f.core_formula? - user = f.path.parent.cd { github_fork } - path = f.path.relative_path_from(HOMEBREW_REPOSITORY) - "https://github.com/#{user}/homebrew/blob/master/#{path}" + if remote = git_origin + path = f.path.relative_path_from(HOMEBREW_REPOSITORY) + github_remote_path(remote, path) + else + f.path + end else f.path end |
