Commit f38a24bd4e0b8c6b7a0c6e441442a1eba9141e5a
- Date: Wed Jun 11 18:20:35 +0000 2008
- Committer: Tim Harper (timcharper@gmail.com)
- Author: Tim Harper (timcharper@gmail.com)
- Commit SHA1: f38a24bd4e0b8c6b7a0c6e441442a1eba9141e5a
- Tree SHA1: 8c40008c09d3ccead6c192b62bd0a0d2167f5df7
auto-expand relative paths passed into Git#status
Commit diff
| |   |
| 206 | 206 | |
| 207 | 207 | def status(file_or_dir = nil, options = {}) |
| 208 | 208 | file_or_dir = file_or_dir.flatten.first if file_or_dir.is_a?(Array) |
| 209 | | file_or_dir = file_or_dir.dup if file_or_dir |
| 210 | 209 | |
| 211 | 210 | results = parse_status(command("status")) |
| 212 | 211 | |
| 213 | 212 | if file_or_dir |
| 214 | | file_or_dir << "/" if File.directory?(file_or_dir) unless /\/$/.match(file_or_dir) |
| 213 | file_or_dir = path_for(file_or_dir).dup |
| 214 | file_or_dir << "/" if File.directory?(file_or_dir) && file_or_dir[-1..-1] != "/" |
| 215 | 215 | results.select do |status| |
| 216 | 216 | if is_a_path?(status[:path]) && /^#{Regexp.escape(status[:path])}/i.match(file_or_dir) |
| 217 | 217 | # promote this status on down and keep it if it's the parent folder of our target file_or_dir |
| toggle raw diff |
--- a/Support/lib/git.rb
+++ b/Support/lib/git.rb
@@ -206,12 +206,12 @@ module SCM
def status(file_or_dir = nil, options = {})
file_or_dir = file_or_dir.flatten.first if file_or_dir.is_a?(Array)
- file_or_dir = file_or_dir.dup if file_or_dir
results = parse_status(command("status"))
if file_or_dir
- file_or_dir << "/" if File.directory?(file_or_dir) unless /\/$/.match(file_or_dir)
+ file_or_dir = path_for(file_or_dir).dup
+ file_or_dir << "/" if File.directory?(file_or_dir) && file_or_dir[-1..-1] != "/"
results.select do |status|
if is_a_path?(status[:path]) && /^#{Regexp.escape(status[:path])}/i.match(file_or_dir)
# promote this status on down and keep it if it's the parent folder of our target file_or_dir |
| |   |
| 69 | 69 | @result[:display].should == "dir/subfolder/" |
| 70 | 70 | end |
| 71 | 71 | |
| 72 | it "should auto-expand the path when filtering to a relative path" do |
| 73 | File.should_receive(:directory?).with("/base/dir/subfolder").and_return(true) |
| 74 | @results = @git.status("dir/subfolder") |
| 75 | @results.should have(1).result |
| 76 | @result = @results.first |
| 77 | @result[:path].should == "/base/dir/subfolder/" |
| 78 | @result[:display].should == "dir/subfolder/" |
| 79 | end |
| 80 | |
| 72 | 81 | it "should parse a status document correctly" do |
| 73 | 82 | result = @git.parse_status_hash(fixture_file("status_output.txt")) |
| 74 | 83 | result.should == {"dir/"=>"?", |
| toggle raw diff |
--- a/Support/spec/lib/commands/status_spec.rb
+++ b/Support/spec/lib/commands/status_spec.rb
@@ -69,6 +69,15 @@ EOF
@result[:display].should == "dir/subfolder/"
end
+ it "should auto-expand the path when filtering to a relative path" do
+ File.should_receive(:directory?).with("/base/dir/subfolder").and_return(true)
+ @results = @git.status("dir/subfolder")
+ @results.should have(1).result
+ @result = @results.first
+ @result[:path].should == "/base/dir/subfolder/"
+ @result[:display].should == "dir/subfolder/"
+ end
+
it "should parse a status document correctly" do
result = @git.parse_status_hash(fixture_file("status_output.txt"))
result.should == {"dir/"=>"?", |