diff options
author | scott Chacon <schacon@agadorsparticus.corp.reactrix.com> | 2007-11-29 11:16:14 -0800 |
---|---|---|
committer | scott Chacon <schacon@agadorsparticus.corp.reactrix.com> | 2007-11-29 11:16:14 -0800 |
commit | 8185e202dfe6a70fb04d3eec7826e4ea54866c4a (patch) | |
tree | 908539c1092cf3231b58d1b4d60c4b11b1d1e649 /lib/git/lib.rb | |
parent | c6db2b7c34eb98a38047fca8fbef4a39279eaf08 (diff) | |
download | third_party-ruby-git-8185e202dfe6a70fb04d3eec7826e4ea54866c4a.tar.gz third_party-ruby-git-8185e202dfe6a70fb04d3eec7826e4ea54866c4a.tar.xz third_party-ruby-git-8185e202dfe6a70fb04d3eec7826e4ea54866c4a.zip |
applied a patch by mateusz jedruch <mateusz.jedruch@gmail.com> for iterating through merge conflicts
Diffstat (limited to 'lib/git/lib.rb')
-rw-r--r-- | lib/git/lib.rb | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/lib/git/lib.rb b/lib/git/lib.rb index cd24fca..ad34709 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -425,7 +425,28 @@ module Git arr_opts << branch.to_a.join(' ') command('merge', arr_opts) end - + + def unmerged + unmerged = [] + command_lines('diff', ["--cached"]).each do |line| + unmerged << $1 if line =~ /^\* Unmerged path (.*)/ + end + unmerged + end + + def conflicts #yields :file, :your, :their + self.unmerged.each do |f| + your = Tempfile.new("YOUR-#{File.basename(f)}").path + arr_opts = [":2:#{f}", ">#{your}"] + command('show', arr_opts) + + their = Tempfile.new("THEIR-#{File.basename(f)}").path + arr_opts = [":3:#{f}", ">#{their}"] + command('show', arr_opts) + yield(f, your, their) + end + end + def remote_add(name, url, opts = {}) arr_opts = ['add'] arr_opts << '-f' if opts[:with_fetch] @@ -549,11 +570,11 @@ module Git private - def command_lines(cmd, opts = {}, chdir = true) + def command_lines(cmd, opts = [], chdir = true) command(cmd, opts, chdir).split("\n") end - def command(cmd, opts = {}, chdir = true) + def command(cmd, opts = [], chdir = true) ENV['GIT_DIR'] = @git_dir if (@git_dir != ENV['GIT_DIR']) ENV['GIT_INDEX_FILE'] = @git_index_file if (@git_index_file != ENV['GIT_INDEX_FILE']) ENV['GIT_WORK_TREE'] = @git_work_dir if (@git_work_dir != ENV['GIT_WORK_TREE']) @@ -564,9 +585,9 @@ module Git out = nil if chdir && (Dir.getwd != path) - Dir.chdir(path) { out = `git #{cmd} #{opts} 2>&1`.chomp } + Dir.chdir(path) { out = `#{git_cmd} 2>&1`.chomp } else - out = `git #{cmd} #{opts} 2>&1`.chomp + out = `#{git_cmd} 2>&1`.chomp end if @logger @@ -584,4 +605,4 @@ module Git end end -end
\ No newline at end of file +end |