summaryrefslogtreecommitdiffstats
path: root/lib/git/lib.rb
diff options
context:
space:
mode:
authorscott Chacon <schacon@agadorsparticus.(none)>2007-11-11 10:04:26 -0800
committerscott Chacon <schacon@agadorsparticus.(none)>2007-11-11 10:04:26 -0800
commita1237671ba3ec38f5b123ee6600e4352dc03196b (patch)
tree71bc13cb36799e778237097b343a4d4fa9189b3f /lib/git/lib.rb
parentefcce7fc123b9e64fb9d93224e4e78d09144af3d (diff)
downloadthird_party-ruby-git-a1237671ba3ec38f5b123ee6600e4352dc03196b.tar.gz
third_party-ruby-git-a1237671ba3ec38f5b123ee6600e4352dc03196b.tar.xz
third_party-ruby-git-a1237671ba3ec38f5b123ee6600e4352dc03196b.zip
git add working, git status object working
Diffstat (limited to 'lib/git/lib.rb')
-rw-r--r--lib/git/lib.rb97
1 files changed, 74 insertions, 23 deletions
diff --git a/lib/git/lib.rb b/lib/git/lib.rb
index 9fa3986..ec65e55 100644
--- a/lib/git/lib.rb
+++ b/lib/git/lib.rb
@@ -52,6 +52,10 @@ module Git
opts[:bare] ? {:repository => clone_dir} : {:working_directory => clone_dir}
end
+
+ ## READ COMMANDS ##
+
+
def log_commits(opts = {})
arr_opts = ['--pretty=oneline']
arr_opts << "-#{opts[:count]}" if opts[:count]
@@ -89,28 +93,6 @@ module Git
arr
end
- def config_get(name)
- command('config', ['--get', name])
- end
-
- def config_list
- hsh = {}
- command_lines('config', ['--list']).each do |line|
- (key, value) = line.split('=')
- hsh[key] = value
- end
- hsh
- 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]]
@@ -161,10 +143,78 @@ module Git
hsh
end
+
+ # compares the index and the working directory
+ def diff_files
+ hsh = {}
+ 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,
+ :sha_file => sha_src, :sha_index => sha_dest, :type => type}
+ end
+ hsh
+ end
+
+ # compares the index and the repository
+ def diff_index(treeish)
+ hsh = {}
+ 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,
+ :sha_repo => sha_src, :sha_index => sha_dest, :type => type}
+ end
+ hsh
+ end
+
+ def ls_files
+ hsh = {}
+ command_lines('ls-files', '--stage').each do |line|
+ (info, file) = line.split("\t")
+ (mode, sha, stage) = info.split
+ hsh[file] = {:path => file, :mode_index => mode, :sha_index => sha, :stage => stage}
+ end
+ hsh
+ 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
+
+ def config_get(name)
+ command('config', ['--get', name])
+ end
+
+ def config_list
+ hsh = {}
+ command_lines('config', ['--list']).each do |line|
+ (key, value) = line.split('=')
+ hsh[key] = value
+ end
+ hsh
+ end
+
+ ## WRITE COMMANDS ##
+
+ def config_set(name, value)
+ command('config', [name, "'#{value}'"])
+ end
+
+ def add(path = '.')
+ command('add', path)
+ end
+
private
- def command_lines(cmd, opts)
+ def command_lines(cmd, opts = {})
command(cmd, opts).split("\n")
end
@@ -177,6 +227,7 @@ module Git
#puts "git #{cmd} #{opts}"
out = `git #{cmd} #{opts} 2>&1`.chomp
#puts out
+ #puts
if $?.exitstatus > 1
raise Git::GitExecuteError.new(out)
end