Module: Zenflow::Branch
- Defined in:
- lib/zenflow/helpers/branch.rb
Class Method Summary collapse
- .apply_merge_strategy(flow, name, destination, rebase_override = false) ⇒ Object
- .checkout(name) ⇒ Object
- .create(name, base) ⇒ Object
- .current(prefix) ⇒ Object
- .delete_local(name, options = {}) ⇒ Object
- .delete_remote(name) ⇒ Object
- .list(prefix) ⇒ Object
- .merge(name) ⇒ Object
- .push(name) ⇒ Object
- .push_tags ⇒ Object
- .rebase(name, source) ⇒ Object
- .tag(name = nil, description = nil) ⇒ Object
- .track(name) ⇒ Object
- .update(name, rebase_override = false) ⇒ Object
Class Method Details
.apply_merge_strategy(flow, name, destination, rebase_override = false) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/zenflow/helpers/branch.rb', line 26 def apply_merge_strategy(flow, name, destination, rebase_override=false) if Zenflow::Config[:merge_strategy] == 'rebase' || rebase_override == true Zenflow::Branch.rebase("#{flow}/#{name}", destination) else Zenflow::Branch.checkout("#{flow}/#{name}") Zenflow::Branch.merge(destination) end end |
.checkout(name) ⇒ Object
63 64 65 66 |
# File 'lib/zenflow/helpers/branch.rb', line 63 def checkout(name) Zenflow::Log("Switching to the #{name} branch") Zenflow::Shell["git checkout #{name}"] end |
.create(name, base) ⇒ Object
35 36 37 38 |
# File 'lib/zenflow/helpers/branch.rb', line 35 def create(name, base) Zenflow::Log("Creating the #{name} branch based on #{base}") Zenflow::Shell["git checkout -b #{name} #{base}"] end |
.current(prefix) ⇒ Object
11 12 13 14 |
# File 'lib/zenflow/helpers/branch.rb', line 11 def current(prefix) branch = Zenflow::Shell.run("git branch | grep '* #{prefix}'", :silent => true) branch.chomp.sub(/\* #{prefix}\/?/, "") unless branch.empty? end |
.delete_local(name, options = {}) ⇒ Object
92 93 94 95 |
# File 'lib/zenflow/helpers/branch.rb', line 92 def delete_local(name, ={}) Zenflow::Log("Removing the local branch") Zenflow::Shell["git branch -#{options[:force] ? 'D' : 'd'} #{name}"] end |
.delete_remote(name) ⇒ Object
83 84 85 86 87 88 89 90 |
# File 'lib/zenflow/helpers/branch.rb', line 83 def delete_remote(name) Zenflow::Log("Removing the remote branch from #{Zenflow::Config[:remote] || 'origin'}") Zenflow::Shell["git branch -r | grep #{Zenflow::Config[:remote] || 'origin'}/#{name} && git push #{Zenflow::Config[:remote] || 'origin'} :#{name} || echo ''"] if Zenflow::Config[:backup_remote] Zenflow::Log("Removing the remote branch from #{Zenflow::Config[:backup_remote]}") Zenflow::Shell["git branch -r | grep #{Zenflow::Config[:backup_remote]}/#{name} && git push #{Zenflow::Config[:backup_remote]} :#{name} || echo ''"] end end |
.list(prefix) ⇒ Object
5 6 7 8 9 |
# File 'lib/zenflow/helpers/branch.rb', line 5 def list(prefix) branches = Zenflow::Shell.run "git branch | grep #{prefix}", :silent => true return ['!! NONE !!'] if branches.empty? branches.split("\n").map{|branch| branch.sub(/.*#{prefix}\/?/, "") } end |
.merge(name) ⇒ Object
73 74 75 76 |
# File 'lib/zenflow/helpers/branch.rb', line 73 def merge(name) Zenflow::Log("Merging in the #{name} branch") Zenflow::Shell["git merge --no-ff #{name}"] end |
.push(name) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/zenflow/helpers/branch.rb', line 40 def push(name) Zenflow::Log("Pushing the #{name} branch to #{Zenflow::Config[:remote] || 'origin'}") Zenflow::Shell["git push #{Zenflow::Config[:remote] || 'origin'} #{name}"] if Zenflow::Config[:backup_remote] Zenflow::Log("Pushing the #{name} branch to #{Zenflow::Config[:backup_remote]}") Zenflow::Shell["git push #{Zenflow::Config[:backup_remote]} #{name}"] end end |
.push_tags ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/zenflow/helpers/branch.rb', line 49 def Zenflow::Log("Pushing tags to #{Zenflow::Config[:remote] || 'origin'}") Zenflow::Shell["git push #{Zenflow::Config[:remote] || 'origin'} --tags"] if Zenflow::Config[:backup_remote] Zenflow::Log("Pushing tags to #{Zenflow::Config[:backup_remote]}") Zenflow::Shell["git push #{Zenflow::Config[:backup_remote]} --tags"] end end |
.rebase(name, source) ⇒ Object
68 69 70 71 |
# File 'lib/zenflow/helpers/branch.rb', line 68 def rebase(name, source) Zenflow::Log("Rebasing #{name} on top of the #{source} branch") Zenflow::Shell["git rebase #{source} #{name}"] end |
.tag(name = nil, description = nil) ⇒ Object
78 79 80 81 |
# File 'lib/zenflow/helpers/branch.rb', line 78 def tag(name=nil, description=nil) Zenflow::Log("Tagging the release") Zenflow::Shell["git tag -a '#{name || Zenflow::Ask('Name of the tag:', :required => true)}' -m '#{Zenflow::Shell.shell_escape_for_single_quoting((description || Zenflow::Ask('Tag message:', :required => true)).to_s)}'"] end |
.track(name) ⇒ Object
58 59 60 61 |
# File 'lib/zenflow/helpers/branch.rb', line 58 def track(name) Zenflow::Log("Tracking the #{name} branch against #{Zenflow::Config[:remote] || 'origin'}/#{name}") Zenflow::Shell["git branch --set-upstream-to=#{Zenflow::Config[:remote] || 'origin'}/#{name} #{name}"] end |
.update(name, rebase_override = false) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/zenflow/helpers/branch.rb', line 16 def update(name, rebase_override=false) if Zenflow::Config[:merge_strategy] == 'rebase' || rebase_override == true Zenflow::Log("Updating the #{name} branch using pull with --rebase") Zenflow::Shell["git checkout #{name} && git pull --rebase"] else Zenflow::Log("Updating the #{name} branch") Zenflow::Shell["git checkout #{name} && git pull"] end end |