Class: Gitflash::Git::Wrapper
- Inherits:
-
Object
- Object
- Gitflash::Git::Wrapper
- Defined in:
- lib/gitflash/git/wrapper.rb
Constant Summary collapse
- HIDDEN_BRANCHES =
%w[–show-current].freeze
Class Method Summary collapse
- .all_local_branches ⇒ Object
- .branch_commits ⇒ Object
- .checkout(branch) ⇒ Object
- .current_branch ⇒ Object
- .delete(branch) ⇒ Object
- .local_branches(current: true, master: true) ⇒ Object
- .reset(commit_hash:, hard:) ⇒ Object
Class Method Details
.all_local_branches ⇒ Object
15 16 17 |
# File 'lib/gitflash/git/wrapper.rb', line 15 def all_local_branches formatted_branches end |
.branch_commits ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/gitflash/git/wrapper.rb', line 39 def branch_commits commits_string = bash.exec('git log --oneline') {}.tap do |hsh| commits_string.each_line do |line| parts = line.strip.split commit_code = parts[0] commit_name = parts[1..].join(' ') label = "#{commit_code} - #{commit_name}" hsh[label] = commit_code end end end |
.checkout(branch) ⇒ Object
23 24 25 |
# File 'lib/gitflash/git/wrapper.rb', line 23 def checkout(branch) bash.system_exec('git', 'checkout', branch) end |
.current_branch ⇒ Object
19 20 21 |
# File 'lib/gitflash/git/wrapper.rb', line 19 def current_branch bash.exec('git branch --show-current').strip end |
.delete(branch) ⇒ Object
27 28 29 |
# File 'lib/gitflash/git/wrapper.rb', line 27 def delete(branch) bash.system_exec('git', 'branch', '-D', *branch) end |
.local_branches(current: true, master: true) ⇒ Object
9 10 11 12 13 |
# File 'lib/gitflash/git/wrapper.rb', line 9 def local_branches(current: true, master: true) formatted_branches.tap do |branches| hidden_branches(current, master).each { |br| branches.delete(br) } end end |
.reset(commit_hash:, hard:) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/gitflash/git/wrapper.rb', line 31 def reset(commit_hash:, hard:) params = [].tap do |ar| ar << '--hard' if hard end bash.system_exec('git', 'reset', *params, commit_hash) end |