Class: Reviewr::Git
- Inherits:
-
Object
- Object
- Reviewr::Git
- Defined in:
- lib/reviewr/git.rb
Direct Known Subclasses
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
- #change_branch(branch_name) ⇒ Object
- #cherry(from, to) ⇒ Object
- #cherry_pick(commit) ⇒ Object
- #commit(msg) ⇒ Object
- #create_branch(branch_name, base) ⇒ Object
- #current_branch ⇒ Object
- #execute(cmd) ⇒ Object
- #fetch(branch_name) ⇒ Object
- #last_commit_body ⇒ Object
- #last_commit_sha ⇒ Object
- #last_commit_subject ⇒ Object
- #log(n) ⇒ Object
- #origin_location ⇒ Object
- #origin_master_commit ⇒ Object
- #push_branch(branch_name) ⇒ Object
- #rebase(base, branch) ⇒ Object
- #user_email ⇒ Object
Instance Attribute Details
#remote_repo ⇒ Object
27 28 29 |
# File 'lib/reviewr/git.rb', line 27 def remote_repo @remote_repo ||= "origin" end |
Class Method Details
.instance ⇒ Object
4 5 6 |
# File 'lib/reviewr/git.rb', line 4 def instance @instance ||= Git.new end |
.instance=(instance) ⇒ Object
8 9 10 |
# File 'lib/reviewr/git.rb', line 8 def instance=(instance) @instance = instance end |
Instance Method Details
#change_branch(branch_name) ⇒ Object
53 54 55 |
# File 'lib/reviewr/git.rb', line 53 def change_branch(branch_name) execute("git checkout #{branch_name}") end |
#cherry(from, to) ⇒ Object
80 81 82 |
# File 'lib/reviewr/git.rb', line 80 def cherry(from, to) execute("git cherry #{from} #{to}") end |
#cherry_pick(commit) ⇒ Object
84 85 86 |
# File 'lib/reviewr/git.rb', line 84 def cherry_pick(commit) execute("git cherry-pick -s #{commit}") end |
#commit(msg) ⇒ Object
44 45 46 |
# File 'lib/reviewr/git.rb', line 44 def commit(msg) execute("git commit --allow-empty -m \"#{msg}\"") end |
#create_branch(branch_name, base) ⇒ Object
40 41 42 |
# File 'lib/reviewr/git.rb', line 40 def create_branch(branch_name, base) execute("git branch #{branch_name} #{base}") end |
#current_branch ⇒ Object
48 49 50 51 |
# File 'lib/reviewr/git.rb', line 48 def current_branch m = execute("git branch").match(/^\* +(\w+)$/) m && m[1] end |
#execute(cmd) ⇒ Object
92 93 94 |
# File 'lib/reviewr/git.rb', line 92 def execute(cmd) `#{cmd}` end |
#fetch(branch_name) ⇒ Object
57 58 59 |
# File 'lib/reviewr/git.rb', line 57 def fetch(branch_name) execute("git fetch #{remote_repo} #{branch_name}") end |
#last_commit_body ⇒ Object
23 24 25 |
# File 'lib/reviewr/git.rb', line 23 def last_commit_body execute(%(git show --pretty=format:"%b:::::" HEAD^)).split(":::::").first end |
#last_commit_sha ⇒ Object
15 16 17 |
# File 'lib/reviewr/git.rb', line 15 def last_commit_sha execute(%(git show --pretty=format:"%H" HEAD)).split("\n").first end |
#last_commit_subject ⇒ Object
19 20 21 |
# File 'lib/reviewr/git.rb', line 19 def last_commit_subject execute(%(git show --pretty=format:"%s" HEAD^)).split("\n").first end |
#log(n) ⇒ Object
88 89 90 |
# File 'lib/reviewr/git.rb', line 88 def log(n) execute("git log -n #{n}") end |
#origin_location ⇒ Object
70 71 72 73 |
# File 'lib/reviewr/git.rb', line 70 def origin_location r = execute("git remote show #{remote_repo}") r && r.match(/URL: (.+)$/)[1] end |
#origin_master_commit ⇒ Object
75 76 77 78 |
# File 'lib/reviewr/git.rb', line 75 def origin_master_commit r = execute("git ls-remote #{remote_repo} refs/heads/master") r && r.split(/\s+/)[0] end |
#push_branch(branch_name) ⇒ Object
66 67 68 |
# File 'lib/reviewr/git.rb', line 66 def push_branch(branch_name) execute("git push #{remote_repo} #{branch_name}") end |
#rebase(base, branch) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/reviewr/git.rb', line 31 def rebase(base, branch) conflict = execute("git rebase #{base} #{branch}").to_s. include?("CONFLICT") if conflict execute('git rebase --abort') end !conflict end |
#user_email ⇒ Object
61 62 63 64 |
# File 'lib/reviewr/git.rb', line 61 def user_email email = execute('git config user.email') email && email.chomp end |