0

I am having trouble trying to find out what files changed between two different commits. Here is the setup, version of Ruby and the Gem Grit, and what happens when I run the program:

> cd /temp
> mkdir tt
> cd tt
> git init
Initialized empty Git repository in C:/temp/tt/.git/
> ruby --version
ruby 1.8.7 (2010-01-10 patchlevel 249) [i386-mingw32]
> gem list grit
*** LOCAL GEMS ***
grit (2.0.0)
> ruby ..\git_diff_test.rb
Commit #1 succeeded.
Commit #2 succeeded.
c:/apps/ruby/lib/ruby/gems/1.8/gems/grit-2.0.0/lib/grit/repo.rb:290:in `diff': wrong number of arguments (4 for 3) (ArgumentError)
        from c:/apps/ruby/lib/ruby/gems/1.8/gems/grit-2.0.0/lib/grit/repo.rb:290:in `diff'
        from ../git_diff_test.rb:13

Here is the ruby program:

require 'rubygems'
require 'grit'
include Grit
File.open('t1.txt', 'w') { |f| f.write('hi/bye') }
repo = Repo.new('.')
repo.add('.')
puts "Commit #1 #{repo.commit_all('1') ? 'succeeded' : 'failed'}."
File.open('t1.txt', 'w') { |f| f.write('hi/bye twice') }
File.open('t2.txt', 'w') { |f| f.write('hi/bye 2') }
repo.add('.')
puts "Commit #2 #{repo.commit_all('2') ? 'succeeded' : 'failed'}."
commits = repo.commits
the_diff = repo.diff(commits[0], commits[1])  # line 13 with the error
p the_diff
John Goodson
  • 191
  • 1
  • 1
  • 3
  • Using the command-line tools, this would be `git diff --numstat commit1..commit2`, but I don't know how to emulate that in Grit. – Phil Miller Jun 11 '10 at 19:23
  • Thanks for the pointer. The call that fails is failing on calling a lower level call which execs out and calls the command line git diff. Calling this lower level function does produce a diff, the problem is setting cmd line options is busted. There is one more problem, unless the ruby program current working dir is in the working tree, it can find the .git dir, so the exec call fails - .add command suffers from this problem as well. As this is a threaded app changing the pwd of it will not work - so I have to write shell scripts that do the work, rather then using the Grit library. – John Goodson Jun 13 '10 at 13:21

1 Answers1

0

you can use

grit.commits_between('HASH1', 'HASH2')

to get list of the two commit

j0k
  • 22,600
  • 28
  • 79
  • 90