diff options
author | scott Chacon <schacon@agadorsparticus.corp.reactrix.com> | 2007-11-09 13:11:22 -0800 |
---|---|---|
committer | scott Chacon <schacon@agadorsparticus.corp.reactrix.com> | 2007-11-09 13:11:22 -0800 |
commit | 9d59d2965184964ab6662282ef5f9ceac2c58552 (patch) | |
tree | f8dd8bf4004eb9403f9ffe2b5c5c708ef877895a /lib/git/lib.rb | |
parent | ab20a674e50268b6c541949c746d77b16a26d15c (diff) | |
download | third_party-ruby-git-9d59d2965184964ab6662282ef5f9ceac2c58552.tar.gz third_party-ruby-git-9d59d2965184964ab6662282ef5f9ceac2c58552.tar.xz third_party-ruby-git-9d59d2965184964ab6662282ef5f9ceac2c58552.zip |
added branches, more log stuff, better tests, changed the log api a bit
added tests for Git::Lib, started Git::Diff development
Diffstat (limited to 'lib/git/lib.rb')
-rw-r--r-- | lib/git/lib.rb | 50 |
1 files changed, 45 insertions, 5 deletions
diff --git a/lib/git/lib.rb b/lib/git/lib.rb index c83ecaa..2937d52 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -3,6 +3,9 @@ module Git class GitExecuteError < StandardError end + class GitNoOutput < StandardError + end + class Lib @base = nil @@ -11,14 +14,15 @@ module Git @base = base end - def log_commits(opts) + 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 + arr_opts << opts[:object] if opts[:object].is_a? String + arr_opts << '-- ' + opts[:path_limiter] if opts[:path_limiter].is_a? String - command_lines('log', arr_opts).map { |l| Git::Object::Commit.new(@base, l.split.first) } + command_lines('log', arr_opts).map { |l| l.split.first } end def revparse(string) @@ -38,7 +42,42 @@ module Git end def branches_all - command_lines('branch', '-a').map { |l| Git::Branch.new(@base, l) } + command_lines('branch', '-a').map do |b| + current = false + current = true if b[0, 2] == '* ' + Git::Branch.new(@base, b.gsub('* ', '').strip, current) + end + end + + def config_remote(name) + hsh = {} + command_lines('config', ['--get-regexp', "remote.#{name}"]).each do |line| + (key, value) = line.split + hsh[key.gsub("remote.#{name}.", '')] = value + end + hsh + end + + # returns hash + # [tree-ish] = [[line_no, match], [line_no, match2]] + # [tree-ish] = [[line_no, match], [line_no, match2]] + def grep(string, opts = {}) + opts[:object] = 'HEAD' if !opts[:object] + + grep_opts = ['-n'] + grep_opts << '-i' if opts[:ignore_case] + grep_opts << '-v' if opts[:invert_match] + grep_opts << "-e '#{string}'" + grep_opts << opts[:object] if opts[:object].is_a? String + grep_opts << ('-- ' + opts[:path_limiter]) if opts[:path_limiter].is_a? String + hsh = {} + command_lines('grep', grep_opts).each do |line| + if m = /(.*)\:(\d+)\:(.*)/.match(line) + hsh[m[1]] ||= [] + hsh[m[1]] << [m[2].to_i, m[3]] + end + end + hsh end private @@ -55,7 +94,8 @@ module Git opts = opts.to_a.join(' ') #puts "git #{cmd} #{opts}" out = `git #{cmd} #{opts} 2>&1`.chomp - if $?.exitstatus != 0 + #puts out + if $?.exitstatus > 1 raise Git::GitExecuteError.new(out) end out |