summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorscott Chacon <schacon@agadorsparticus.(none)>2007-11-11 14:37:05 -0800
committerscott Chacon <schacon@agadorsparticus.(none)>2007-11-11 14:37:05 -0800
commitb81ee9305f418209ba0d77fbb7b47b23d4b121ca (patch)
treef4bef02a3befcbe06be85ff8507cb18242df5f40 /lib
parentabcb1453e210beb6de70a69d3501cf842b38636e (diff)
downloadthird_party-ruby-git-b81ee9305f418209ba0d77fbb7b47b23d4b121ca.tar.gz
third_party-ruby-git-b81ee9305f418209ba0d77fbb7b47b23d4b121ca.tar.xz
third_party-ruby-git-b81ee9305f418209ba0d77fbb7b47b23d4b121ca.zip
added merging functions
Diffstat (limited to 'lib')
-rw-r--r--lib/git/base.rb11
-rw-r--r--lib/git/branch.rb32
-rw-r--r--lib/git/lib.rb13
3 files changed, 53 insertions, 3 deletions
diff --git a/lib/git/base.rb b/lib/git/base.rb
index 342d535..0b837cb 100644
--- a/lib/git/base.rb
+++ b/lib/git/base.rb
@@ -156,7 +156,7 @@ module Git
def reset_hard(commitish = nil, opts = {})
opts = {:hard => true}.merge(opts)
- self.lib.reset(path, opts)
+ self.lib.reset(commitish, opts)
end
def commit(message, opts = {})
@@ -172,11 +172,20 @@ module Git
self.lib.checkout(branch, opts)
end
+ def merge(branch, message = 'merge')
+ self.lib.merge(branch, message)
+ end
+
# convenience methods
def revparse(objectish)
self.lib.revparse(objectish)
end
+
+ def current_branch
+ self.lib.branch_current
+ end
+
end
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
diff --git a/lib/git/lib.rb b/lib/git/lib.rb
index 41b3efb..9b3922e 100644
--- a/lib/git/lib.rb
+++ b/lib/git/lib.rb
@@ -257,6 +257,14 @@ module Git
command('checkout', arr_opts)
end
+ def merge(branch, message = nil)
+ arr_opts = []
+ arr_opts << ["-m '#{message}'"] if message
+ arr_opts << branch.to_a.join(' ')
+ command('merge', arr_opts)
+ end
+
+
private
def command_lines(cmd, opts = {})
@@ -278,7 +286,10 @@ module Git
#puts "git #{cmd} #{opts}"
#puts out
#puts
- if $?.exitstatus > 1
+ if $?.exitstatus > 0
+ if $?.exitstatus == 1 && out == ''
+ return ''
+ end
raise Git::GitExecuteError.new(out)
end
out