Skip to content

Instantly share code, notes, and snippets.

@schacon
Created August 6, 2008 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schacon/4262 to your computer and use it in GitHub Desktop.
Save schacon/4262 to your computer and use it in GitHub Desktop.
From 1feae123089ec8c205c805edbe58f63f4c3cfe14 Mon Sep 17 00:00:00 2001
From: Scott Chacon <schacon@gmail.com>
Date: Wed, 6 Aug 2008 12:35:34 -0700
Subject: [PATCH] updated grit to use the working directory for status
---
vendor/gems/grit/lib/grit/repo.rb | 2 ++
vendor/gems/grit/lib/grit/status.rb | 32 +++++++++++++++++---------------
2 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/vendor/gems/grit/lib/grit/repo.rb b/vendor/gems/grit/lib/grit/repo.rb
index 16d979c..6d3ff9e 100644
--- a/vendor/gems/grit/lib/grit/repo.rb
+++ b/vendor/gems/grit/lib/grit/repo.rb
@@ -5,6 +5,7 @@ module Grit
# The path of the git repo as a String
attr_accessor :path
+ attr_accessor :working_dir
attr_reader :bare
# The git command line interface object
@@ -22,6 +23,7 @@ module Grit
epath = File.expand_path(path)
if File.exist?(File.join(epath, '.git'))
+ self.working_dir = epath
self.path = File.join(epath, '.git')
@bare = false
elsif File.exist?(epath) && (epath =~ /\.git$/ || options[:is_bare])
diff --git a/vendor/gems/grit/lib/grit/status.rb b/vendor/gems/grit/lib/grit/status.rb
index 25afc1c..92c48ab 100644
--- a/vendor/gems/grit/lib/grit/status.rb
+++ b/vendor/gems/grit/lib/grit/status.rb
@@ -88,25 +88,27 @@ module Grit
def construct_status
@files = ls_files
- # find untracked in working dir
- Dir.glob('**/*') do |file|
- if !@files[file]
- @files[file] = {:path => file, :untracked => true} if !File.directory?(file)
+ Dir.chdir(@base.working_dir) do
+ # find untracked in working dir
+ Dir.glob('**/*') do |file|
+ if !@files[file]
+ @files[file] = {:path => file, :untracked => true} if !File.directory?(file)
+ end
end
- end
- # find modified in tree
- diff_files.each do |path, data|
- @files[path] ? @files[path].merge!(data) : @files[path] = data
- end
+ # find modified in tree
+ diff_files.each do |path, data|
+ @files[path] ? @files[path].merge!(data) : @files[path] = data
+ end
- # find added but not committed - new files
- diff_index('HEAD').each do |path, data|
- @files[path] ? @files[path].merge!(data) : @files[path] = data
- end
+ # find added but not committed - new files
+ diff_index('HEAD').each do |path, data|
+ @files[path] ? @files[path].merge!(data) : @files[path] = data
+ end
- @files.each do |k, file_hash|
- @files[k] = StatusFile.new(@base, file_hash)
+ @files.each do |k, file_hash|
+ @files[k] = StatusFile.new(@base, file_hash)
+ end
end
end
--
1.5.6.GIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment