diff options
| author | Martin Afanasjew | 2016-07-02 09:39:00 +0200 |
|---|---|---|
| committer | Martin Afanasjew | 2016-07-07 01:46:58 +0200 |
| commit | 6cdc6b1460c2d81d514f03afa3447c81b75ef801 (patch) | |
| tree | 4274c708d92c4891b8dc10fe84a20a0eb29662bd /Library/Homebrew/extend/git_repository.rb | |
| parent | ec75ca7e42b35ae2932ca3feacfd97e2aab5d278 (diff) | |
| download | brew-6cdc6b1460c2d81d514f03afa3447c81b75ef801.tar.bz2 | |
Add GitRepositoryExtension
Add an extension for accessing Git-related meta data that can be mixed
in into a Pathname object (e.g. `HOMBREW_REPOSITORY` or the path of a
`Tap` instance). The goal here is to eliminate code duplication.
Diffstat (limited to 'Library/Homebrew/extend/git_repository.rb')
| -rw-r--r-- | Library/Homebrew/extend/git_repository.rb | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/Library/Homebrew/extend/git_repository.rb b/Library/Homebrew/extend/git_repository.rb new file mode 100644 index 000000000..c15988550 --- /dev/null +++ b/Library/Homebrew/extend/git_repository.rb @@ -0,0 +1,47 @@ +require "utils/git" +require "utils/popen" + +module GitRepositoryExtension + def git? + join(".git").exist? + end + + def git_origin + return unless git? && Utils.git_available? + cd do + Utils.popen_read("git", "config", "--get", "remote.origin.url").chuzzle + end + end + + def git_head + return unless git? && Utils.git_available? + cd do + Utils.popen_read("git", "rev-parse", "--verify", "-q", "HEAD").chuzzle + end + end + + def git_short_head + return unless git? && Utils.git_available? + cd do + Utils.popen_read( + "git", "rev-parse", "--short=4", "--verify", "-q", "HEAD" + ).chuzzle + end + end + + def git_last_commit + return unless git? && Utils.git_available? + cd do + Utils.popen_read("git", "show", "-s", "--format=%cr", "HEAD").chuzzle + end + end + + def git_last_commit_date + return unless git? && Utils.git_available? + cd do + Utils.popen_read( + "git", "show", "-s", "--format=%cd", "--date=short", "HEAD" + ).chuzzle + end + end +end |
