diff options
Diffstat (limited to 'lib/git/branch.rb')
-rw-r--r-- | lib/git/branch.rb | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/lib/git/branch.rb b/lib/git/branch.rb index 3d8337b..1d4b64c 100644 --- a/lib/git/branch.rb +++ b/lib/git/branch.rb @@ -27,7 +27,24 @@ module Git def checkout check_if_create - @base.lib.checkout(@name) + @base.checkout(@name) + end + + + # g.branch('new_branch').in_branch do + # # create new file + # # do other stuff + # return true # auto commits and switches back + # end + def in_branch (message = 'in branch work') + old_current = @base.lib.branch_current + checkout + if yield + @base.commit_all(message) + else + @base.reset_hard + end + @base.checkout(old_current) end def create @@ -42,6 +59,19 @@ module Git determine_current end + def merge(branch = nil, message = nil) + if branch + in_branch do + @base.merge(branch, message) + false + end + # merge a branch into this one + else + # merge this branch into the current one + @base.merge(@name) + end + end + def to_s @name end |