Module: Maximus::GitHelper
- Included in:
- GitControl
- Defined in:
- lib/maximus/git_helper.rb
Overview
Methods used for git commands
Instance Method Summary collapse
-
#branch ⇒ String
Get current branch name.
-
#commit_information(commit_sha) ⇒ Object
A commit’s insertions, deletions, and file names.
-
#files_by_sha(commit_sha) ⇒ Object
Grab files by sha.
-
#first_commit ⇒ String
Find first commit.
-
#head_sha ⇒ String
Get last commit on current branch.
-
#lines_by_sha(commit_sha) ⇒ Array
Retrieve insertions by commit with a custom script.
-
#master_commit_sha ⇒ String
Get last commit sha on the master branch.
-
#previous_commit(current_commit = head_sha, previous_by = 1) ⇒ String
Get commit before current.
-
#remote ⇒ String?
Get remote URL.
-
#sha_range(sha1, sha2) ⇒ Object
Retrieve list of shas between two commits.
-
#working_copy_files ⇒ Object
Return file names of working copy files.
Instance Method Details
#branch ⇒ String
Get current branch name
30 31 32 |
# File 'lib/maximus/git_helper.rb', line 30 def branch `env -i git rev-parse --abbrev-ref HEAD`.strip! end |
#commit_information(commit_sha) ⇒ Object
A commit’s insertions, deletions, and file names
66 67 68 69 |
# File 'lib/maximus/git_helper.rb', line 66 def commit_information(commit_sha) # Start after the commit message `git -C #{@config.working_dir} log --numstat --oneline #{commit_sha}`.split("\n")[1..-1] end |
#files_by_sha(commit_sha) ⇒ Object
Grab files by sha
54 55 56 |
# File 'lib/maximus/git_helper.rb', line 54 def files_by_sha(commit_sha) `git -C #{@config.working_dir} show --pretty="format:" --name-only #{commit_sha}` end |
#first_commit ⇒ String
Find first commit
9 10 11 |
# File 'lib/maximus/git_helper.rb', line 9 def first_commit `git -C #{@config.working_dir} rev-list --max-parents=0 HEAD`.strip! end |
#head_sha ⇒ String
Get last commit on current branch
24 25 26 |
# File 'lib/maximus/git_helper.rb', line 24 def head_sha @g.object('HEAD').sha end |
#lines_by_sha(commit_sha) ⇒ Array
Retrieve insertions by commit with a custom script
74 75 76 |
# File 'lib/maximus/git_helper.rb', line 74 def lines_by_sha(commit_sha) `#{File.join(File.dirname(__FILE__), 'reporter', 'git-lines.sh')} #{@config.working_dir} #{commit_sha}`.split("\n") end |
#master_commit_sha ⇒ String
Get last commit sha on the master branch
36 37 38 |
# File 'lib/maximus/git_helper.rb', line 36 def master_commit_sha @g.branches[:master].blank? ? head_sha : @g.branches[:master].gcommit.sha end |
#previous_commit(current_commit = head_sha, previous_by = 1) ⇒ String
Get commit before current
18 19 20 |
# File 'lib/maximus/git_helper.rb', line 18 def previous_commit(current_commit = head_sha, previous_by = 1) `git -C #{@config.working_dir} rev-list --max-count=#{previous_by + 1} #{current_commit} --reverse | head -n1`.strip! end |
#remote ⇒ String?
Get remote URL
42 43 44 |
# File 'lib/maximus/git_helper.rb', line 42 def remote @g.remotes.first.url unless @g.remotes.blank? end |
#sha_range(sha1, sha2) ⇒ Object
Retrieve list of shas between two commits
60 61 62 |
# File 'lib/maximus/git_helper.rb', line 60 def sha_range(sha1, sha2) `git -C #{@config.working_dir} rev-list #{sha1}..#{sha2} --no-merges` end |
#working_copy_files ⇒ Object
Return file names of working copy files
48 49 50 |
# File 'lib/maximus/git_helper.rb', line 48 def working_copy_files `git -C #{@config.working_dir} diff --name-only` end |