summaryrefslogtreecommitdiffstats
path: root/lib/git/lib.rb
diff options
context:
space:
mode:
authorscott Chacon <schacon@agadorsparticus.corp.reactrix.com>2007-11-08 17:07:04 -0800
committerscott Chacon <schacon@agadorsparticus.corp.reactrix.com>2007-11-08 17:07:04 -0800
commit1f63953f05a4afe74f881d54f69f77da513939d5 (patch)
tree5fabd81a82d8aa3df0e9cdc10b0ed7f6ff141b8a /lib/git/lib.rb
parentb18bca3b853dee6a7bc86f09921aa3b1ee3f3d7b (diff)
downloadthird_party-ruby-git-1f63953f05a4afe74f881d54f69f77da513939d5.tar.gz
third_party-ruby-git-1f63953f05a4afe74f881d54f69f77da513939d5.tar.xz
third_party-ruby-git-1f63953f05a4afe74f881d54f69f77da513939d5.zip
moved the git objects into the object.rb file
Diffstat (limited to 'lib/git/lib.rb')
-rw-r--r--lib/git/lib.rb46
1 files changed, 41 insertions, 5 deletions
diff --git a/lib/git/lib.rb b/lib/git/lib.rb
index 3df049c..595f294 100644
--- a/lib/git/lib.rb
+++ b/lib/git/lib.rb
@@ -1,21 +1,57 @@
module Git
+
+ class GitExecuteError < StandardError
+ end
+
class Lib
-
+
@base = nil
def initialize(base)
@base = base
end
- def log_shas(count)
- command('log', "-#{count} --pretty=oneline").split("\n").map { |l| Git::Commit.new(l.split.first) }
+ def log_commits(opts)
+ arr_opts = ['--pretty=oneline']
+ arr_opts << "-#{opts[:count]}" if opts[:count]
+ arr_opts << "--since=\"#{opts[:since]}\"" if opts[:since].is_a? String
+ arr_opts << "#{opts[:between][0]}..#{opts[:between][1].to_s}" if (opts[:between] && opts[:between].size == 2)
+ arr_opts << opts[:file] if opts[:file].is_a? String
+
+ command('log', arr_opts).split("\n").map { |l| Git::Commit.new(l.split.first) }
+ end
+
+ def revparse(string)
+ command('rev-parse', string)
+ end
+
+ def object_type(sha)
+ command('cat-file', ['-t', sha])
+ end
+
+ def object_size(sha)
+ command('cat-file', ['-s', sha])
+ end
+
+ def object_contents(sha)
+ command('cat-file', ['-p', sha])
end
private
def command(cmd, opts)
- ENV['GIT_DIR'] = @base.repo.path
- `git #{cmd} #{opts}`
+ ENV['GIT_DIR'] = @base.repo.path
+ ENV['GIT_INDEX_FILE'] = @base.index.path
+ ENV['GIT_WORK_DIR'] = @base.dir.path
+ Dir.chdir(@base.dir.path) do
+ opts = opts.to_a.join(' ')
+ #puts "git #{cmd} #{opts}"
+ out = `git #{cmd} #{opts} 2>&1`.chomp
+ if $?.exitstatus != 0
+ raise Git::GitExecuteError.new(out)
+ end
+ out
+ end
end
end