summaryrefslogtreecommitdiffstats
path: root/lib/git
diff options
context:
space:
mode:
authorscott Chacon <schacon@agadorsparticus.(none)>2007-11-11 10:43:27 -0800
committerscott Chacon <schacon@agadorsparticus.(none)>2007-11-11 10:43:27 -0800
commita4fa110279ea28873fe1e4df10c89ddc591046b4 (patch)
tree60e08ccf8caca2fe428dee76c06c102cc54bc98b /lib/git
parenta1237671ba3ec38f5b123ee6600e4352dc03196b (diff)
downloadthird_party-ruby-git-a4fa110279ea28873fe1e4df10c89ddc591046b4.tar.gz
third_party-ruby-git-a4fa110279ea28873fe1e4df10c89ddc591046b4.tar.xz
third_party-ruby-git-a4fa110279ea28873fe1e4df10c89ddc591046b4.zip
added the commit(), changed base.commit, base.tree, base.blob to gcommit, gtree, gblob
Diffstat (limited to 'lib/git')
-rw-r--r--lib/git/base.rb15
-rw-r--r--lib/git/lib.rb21
-rw-r--r--lib/git/status.rb23
3 files changed, 45 insertions, 14 deletions
diff --git a/lib/git/base.rb b/lib/git/base.rb
index eded12d..9be9fec 100644
--- a/lib/git/base.rb
+++ b/lib/git/base.rb
@@ -107,9 +107,9 @@ module Git
def object(objectish)
Git::Object.new(self, objectish)
end
- alias_method :tree, :object
- alias_method :commit, :object
- alias_method :blob, :object
+ alias_method :gtree, :object
+ alias_method :gcommit, :object
+ alias_method :gblob, :object
def log(count = 30)
@@ -140,6 +140,15 @@ module Git
def add(path = '.')
self.lib.add(path)
end
+
+ def commit(message, opts = {})
+ self.lib.commit(message, opts)
+ end
+
+ def commit_all(message, opts = {})
+ opts = {:add_all => true}.merge(opts)
+ self.lib.commit(message, opts)
+ end
# convenience methods
diff --git a/lib/git/lib.rb b/lib/git/lib.rb
index ec65e55..d0dda8b 100644
--- a/lib/git/lib.rb
+++ b/lib/git/lib.rb
@@ -150,7 +150,7 @@ module Git
command_lines('diff-files').each do |line|
(info, file) = line.split("\t")
(mode_src, mode_dest, sha_src, sha_dest, type) = info.split
- hsh[file] = {:path => file, :mode_file => mode_src, :mode_index => mode_dest,
+ hsh[file] = {:path => file, :mode_file => mode_src.to_s[1, 7], :mode_index => mode_dest,
:sha_file => sha_src, :sha_index => sha_dest, :type => type}
end
hsh
@@ -162,7 +162,7 @@ module Git
command_lines('diff-index', treeish).each do |line|
(info, file) = line.split("\t")
(mode_src, mode_dest, sha_src, sha_dest, type) = info.split
- hsh[file] = {:path => file, :mode_repo => mode_src, :mode_index => mode_dest,
+ hsh[file] = {:path => file, :mode_repo => mode_src.to_s[1, 7], :mode_index => mode_dest,
:sha_repo => sha_src, :sha_index => sha_dest, :type => type}
end
hsh
@@ -208,10 +208,16 @@ module Git
end
def add(path = '.')
+ path = path.join(' ') if path.is_a?(Array)
command('add', path)
end
-
+ def commit(message, opts = {})
+ arr_opts = ["-m '#{message}'"]
+ arr_opts << '-a' if opts[:add_all]
+ command('commit', arr_opts)
+ end
+
private
def command_lines(cmd, opts = {})
@@ -222,10 +228,15 @@ module Git
ENV['GIT_DIR'] = @git_dir if @git_dir
ENV['GIT_INDEX_FILE'] = @git_index_file if @git_index_file
ENV['GIT_WORK_DIR'] = @git_work_dir if @git_work_dir
- Dir.chdir(@git_work_dir || @git_dir || @path) do
+ path = @git_work_dir || @git_dir || @path
+ Dir.chdir(path) do
opts = opts.to_a.join(' ')
- #puts "git #{cmd} #{opts}"
out = `git #{cmd} #{opts} 2>&1`.chomp
+ #puts path
+ #puts "gd: #{@git_work_dir}"
+ #puts "gi: #{@git_index_file}"
+ #puts "pp: #{@path}"
+ #puts "git #{cmd} #{opts}"
#puts out
#puts
if $?.exitstatus > 1
diff --git a/lib/git/status.rb b/lib/git/status.rb
index 24fd98d..f738644 100644
--- a/lib/git/status.rb
+++ b/lib/git/status.rb
@@ -27,8 +27,8 @@ module Git
out = ''
self.each do |file|
out << file.path
- out << "\n\tsha(r) " + file.sha_repo.to_s
- out << "\n\tsha(i) " + file.sha_index.to_s
+ out << "\n\tsha(r) " + file.sha_repo.to_s + ' ' + file.mode_repo.to_s
+ out << "\n\tsha(i) " + file.sha_index.to_s + ' ' + file.mode_index.to_s
out << "\n\ttype " + file.type.to_s
out << "\n\tstage " + file.stage.to_s
out << "\n\tuntrac " + file.untracked.to_s
@@ -55,7 +55,10 @@ module Git
attr_accessor :mode_index, :mode_repo
attr_accessor :sha_index, :sha_repo
- def initialize(hash)
+ @base = nil
+
+ def initialize(base, hash)
+ @base = base
@path = hash[:path]
@type = hash[:type]
@stage = hash[:stage]
@@ -66,6 +69,14 @@ module Git
@untracked = hash[:untracked]
end
+ def blob(type = :index)
+ if type == :repo
+ @base.object(@sha_repo)
+ else
+ @base.object(@sha_index) rescue @base.object(@sha_repo)
+ end
+ end
+
end
@@ -85,16 +96,16 @@ module Git
# find modified in tree
@base.lib.diff_files.each do |path, data|
- @files[path].merge!(data)
+ @files[path] ? @files[path].merge!(data) : @files[path] = data
end
# find added but not committed - new files
@base.lib.diff_index('HEAD').each do |path, data|
- @files[path].merge!(data)
+ @files[path] ? @files[path].merge!(data) : @files[path] = data
end
@files.each do |k, file_hash|
- @files[k] = StatusFile.new(file_hash)
+ @files[k] = StatusFile.new(@base, file_hash)
end
end