Method: Gitgo::Git#merge

Defined in:
lib/gitgo/git.rb

#merge(treeish = upstream_branch) ⇒ Object

Merges the specified reference with the current branch, fast-forwarding when possible. This method does not need to checkout the branch into a working directory to perform the merge.



616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
# File 'lib/gitgo/git.rb', line 616

def merge(treeish=upstream_branch)
  sandbox do |git, work_tree, index_file|
    des, src = safe_rev_parse(branch, treeish)
    base = des.nil? ? nil : git.merge_base({}, des, src).chomp("\n")
    
    case
    when base == src
      break
    when base == des
      # fast forward situation
      grit.update_ref(branch, src)
    else
      # todo: add rebase as an option
      
      git.read_tree({
        :m => true,          # merge
        :i => true,          # without a working tree
        :trivial => true,    # only merge if no file-level merges are required
        :aggressive => true, # allow resolution of removes
        :index_output => index_file
      }, base, branch, src)
      
      commit!("gitgo merge of #{treeish} into #{branch}", 
        :tree => git.write_tree.chomp("\n"),
        :parents => [des, src]
      )
    end
    
    reset
  end
  
  self
end