summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--TODO6
-rw-r--r--lib/git/lib.rb23
-rw-r--r--tests/files/working.git/refs/heads/master2
3 files changed, 24 insertions, 7 deletions
diff --git a/TODO b/TODO
index a8c73d1..a0fa7ba 100644
--- a/TODO
+++ b/TODO
@@ -1,15 +1,17 @@
* more documentation
-* git revert, stash, rebase
* more low level index actions
- (with_index), checkout-index, read-tree, write-tree, update-ref
-* submodule support
+* git revert, stash, rebase
* diff additions
- annotate, blame
+
+* submodule support
+
* repository admin
- prune, fsck, pack-refs, gc, count-objects, unpack-objects
diff --git a/lib/git/lib.rb b/lib/git/lib.rb
index 6bddef0..71f3555 100644
--- a/lib/git/lib.rb
+++ b/lib/git/lib.rb
@@ -15,8 +15,8 @@ module Git
def initialize(base = nil)
if base.is_a?(Git::Base)
@git_dir = base.repo.path
- @git_index_file = base.index.path
- @git_work_dir = base.dir.path
+ @git_index_file = base.index.path if base.index
+ @git_work_dir = base.dir.path if base.dir
elsif base.is_a?(Hash)
@git_dir = base[:repository]
@git_index_file = base[:index]
@@ -389,17 +389,32 @@ module Git
def command(cmd, opts = {})
ENV['GIT_DIR'] = @git_dir
- ENV['GIT_INDEX_FILE'] = @git_index_file
- ENV['GIT_WORK_DIR'] = @git_work_dir
+
+ if @git_index_file
+ ENV['GIT_INDEX_FILE'] = @git_index_file
+ else
+ ENV['GIT_INDEX_FILE'].delete rescue nil
+ end
+
+ if @git_work_dir
+ ENV['GIT_WORK_TREE'] = @git_work_dir if @git_work_dir
+ else
+ ENV['GIT_WORK_TREE'].delete rescue nil
+ end
+
path = @git_work_dir || @git_dir || @path
Dir.chdir(path) do
opts = opts.to_a.join(' ')
git_cmd = "git #{cmd} #{opts}"
out = `git #{cmd} #{opts} 2>&1`.chomp
#puts path
+ #puts "gr: #{@git_dir}"
#puts "gd: #{@git_work_dir}"
#puts "gi: #{@git_index_file}"
#puts "pp: #{@path}"
+ #puts ENV['GIT_DIR']
+ #puts ENV['GIT_WORK_TREE']
+ #puts ENV['GIT_INDEX_FILE']
#puts git_cmd
#puts out
#puts
diff --git a/tests/files/working.git/refs/heads/master b/tests/files/working.git/refs/heads/master
index 4b03b19..6f2e7bd 100644
--- a/tests/files/working.git/refs/heads/master
+++ b/tests/files/working.git/refs/heads/master
@@ -1 +1 @@
-545ffc79786f268524c35e1e05b1770c7c74faf1
+5e392652a881999392c2757cf9b783c5d47b67f7