Module: Legit::Helpers
- Included in:
- CLI
- Defined in:
- lib/legit/helpers.rb
Constant Summary collapse
- LOG_BASE_COMMAND =
"git log --pretty=format:'%C(yellow)%h%Creset%C(bold cyan)%d%Creset %s %Cgreen(%cr)%Creset %C(bold magenta) <%an>%Creset' --graph --abbrev-commit --date=relative"
Instance Method Summary collapse
- #delete_local_branch!(branch_name) ⇒ Object
- #delete_remote_branch!(branch_name) ⇒ Object
- #delete_remote_branch?(branch_name) ⇒ Boolean
- #force_delete_local_branch!(branch_name) ⇒ Object
- #force_delete_local_branch?(branch_name) ⇒ Boolean
- #local_branches ⇒ Object
- #repo ⇒ Object
- #run_command(command) ⇒ Object
- #todos_staged?(todo_format) ⇒ Boolean
Instance Method Details
#delete_local_branch!(branch_name) ⇒ Object
16 17 18 19 |
# File 'lib/legit/helpers.rb', line 16 def delete_local_branch!(branch_name) run_command("git branch -d #{branch_name}") $?.success? end |
#delete_remote_branch!(branch_name) ⇒ Object
43 44 45 |
# File 'lib/legit/helpers.rb', line 43 def delete_remote_branch!(branch_name) run_command("git push --delete origin #{branch_name}") end |
#delete_remote_branch?(branch_name) ⇒ Boolean
34 35 36 37 38 39 40 41 |
# File 'lib/legit/helpers.rb', line 34 def delete_remote_branch?(branch_name) if yes?("Delete branch remotely?", :red) delete_remote_branch!(branch_name) true else false end end |
#force_delete_local_branch!(branch_name) ⇒ Object
30 31 32 |
# File 'lib/legit/helpers.rb', line 30 def force_delete_local_branch!(branch_name) run_command("git branch -D #{branch_name}") end |
#force_delete_local_branch?(branch_name) ⇒ Boolean
21 22 23 24 25 26 27 28 |
# File 'lib/legit/helpers.rb', line 21 def force_delete_local_branch?(branch_name) if yes?("Force delete branch?", :red) force_delete_local_branch!(branch_name) true else false end end |
#local_branches ⇒ Object
12 13 14 |
# File 'lib/legit/helpers.rb', line 12 def local_branches repo.branches.select { |b| b.branch? } end |
#repo ⇒ Object
8 9 10 |
# File 'lib/legit/helpers.rb', line 8 def repo @repo ||= Rugged::Repository.new(Rugged::Repository.discover) end |
#run_command(command) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/legit/helpers.rb', line 47 def run_command(command) = { :verbose => ENV.has_key?('LEGIT_DEBUG') } run(command, ) end |
#todos_staged?(todo_format) ⇒ Boolean
54 55 56 57 |
# File 'lib/legit/helpers.rb', line 54 def todos_staged?(todo_format) run_command("git diff --staged | grep '^+' | grep #{todo_format}") $?.success? # grep returns 0 if there is a match end |