Merge pull request #842 from ariasuni/dont-aggregate-git-ignored-status2

Fix deducing git ignored state for files too, not only directories
This commit is contained in:
Benjamin Sago 2021-04-11 20:33:56 +01:00 committed by GitHub
commit 051a46c643
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 69 additions and 29 deletions

View File

@ -300,6 +300,8 @@ touch "ignoreds/music.m4a"
mkdir "ignoreds/nested" mkdir "ignoreds/nested"
touch "ignoreds/nested/70s grove.mp3" touch "ignoreds/nested/70s grove.mp3"
touch "ignoreds/nested/funky chicken.m4a" touch "ignoreds/nested/funky chicken.m4a"
mkdir "ignoreds/nested2"
touch "ignoreds/nested2/ievan polkka.mp3"
mkdir "target" mkdir "target"
touch "target/another ignored file" touch "target/another ignored file"

View File

@ -242,21 +242,30 @@ impl Git {
else { self.file_status(index) } else { self.file_status(index) }
} }
/// Get the status for the file at the given path. /// Get the user-facing status of a file.
/// We check the statuses directly applying to a file, and for the ignored
/// status we check if any of its parents directories is ignored by git.
fn file_status(&self, file: &Path) -> f::Git { fn file_status(&self, file: &Path) -> f::Git {
let path = reorient(file); let path = reorient(file);
self.statuses.iter() let s = self.statuses.iter()
.find(|p| p.0.as_path() == path) .filter(|p| if p.1 == git2::Status::IGNORED {
.map(|&(_, s)| f::Git { staged: index_status(s), unstaged: working_tree_status(s) }) path.starts_with(&p.0)
.unwrap_or_default() } else {
p.0 == path
})
.fold(git2::Status::empty(), |a, b| a | b.1);
let staged = index_status(s);
let unstaged = working_tree_status(s);
f::Git { staged, unstaged }
} }
/// Get the combined, user-facing status of a file or directory. /// Get the combined, user-facing status of a directory.
/// Statuses are aggregating (for example, a directory is considered /// Statuses are aggregating (for example, a directory is considered
/// modified if any file under it has the status modified), except /// modified if any file under it has the status modified), except for
/// for ignored which applies to files under (for example, a file is /// ignored status which applies to files under (for example, a directory
/// considered ignored if one of its parent directories is ignored) /// is considered ignored if one of its parent directories is ignored).
fn dir_status(&self, dir: &Path) -> f::Git { fn dir_status(&self, dir: &Path) -> f::Git {
let path = reorient(dir); let path = reorient(dir);

View File

@ -101,13 +101,21 @@ status = 0
tags = [ 'long', 'git' ] tags = [ 'long', 'git' ]
[[cmd]] [[cmd]]
name = "exa --git -l with an ignored directory argument does not flag the contents as ignored" name = "exa --git -l with an ignored directory argument flags the contents as ignored"
shell = "exa --git -l /testcases/git2/target" shell = "exa --git -l /testcases/git2/target"
stdout = { file = "outputs/git2_long_ignoreddir.ansitxt" } stdout = { file = "outputs/git2_long_ignoreddir.ansitxt" }
stderr = { empty = true } stderr = { empty = true }
status = 0 status = 0
tags = [ 'long', 'git' ] tags = [ 'long', 'git' ]
[[cmd]]
name = "exa --git -l --list-dirs with a directory argument doesnt flag it as ignored if only the content is"
shell = "exa --git -l --list-dirs /testcases/git2/ignoreds/nested2"
stdout = { file = "outputs/git2_long_ignoredcontent.ansitxt" }
stderr = { empty = true }
status = 0
tags = [ 'long', 'git' ]
[[cmd]] [[cmd]]
name = "exa --git -l with a nested repository argument uses the sub-repository rules" name = "exa --git -l with a nested repository argument uses the sub-repository rules"
shell = "exa --git -l /testcases/git2/deeply/nested/repository" shell = "exa --git -l /testcases/git2/deeply/nested/repository"
@ -155,7 +163,7 @@ status = 0
tags = [ 'long', 'git' ] tags = [ 'long', 'git' ]
[[cmd]] [[cmd]]
name = "exa --git -l shows a Git status column for multiple repositories across multiple directories" name = "exa --git -l shows a Git status column for multiple repositories across multiple directories 2"
shell = "exa --git -l /testcases/{git2/deeply/nested/directory,git/edits,git2/target,git2/deeply,git}" shell = "exa --git -l /testcases/{git2/deeply/nested/directory,git/edits,git2/target,git2/deeply,git}"
stdout = { file = "outputs/git1+2_long_nested.ansitxt" } stdout = { file = "outputs/git1+2_long_nested.ansitxt" }
stderr = { empty = true } stderr = { empty = true }

View File

@ -8,7 +8,7 @@
.rw-rw-r-- 20 cassowary  1 Jan 12:34 -M unstaged .rw-rw-r-- 20 cassowary  1 Jan 12:34 -M unstaged
/testcases/git2/target: /testcases/git2/target:
.rw-rw-r-- 0 cassowary  1 Jan 12:34 -- another ignored file .rw-rw-r-- 0 cassowary  1 Jan 12:34 -I another ignored file
/testcases/git2/deeply: /testcases/git2/deeply:
drwxrwxr-x - cassowary  1 Jan 12:34 -N nested drwxrwxr-x - cassowary  1 Jan 12:34 -N nested

View File

@ -1 +1 @@
music.m4a nested music.m4a nested nested2

View File

@ -1,2 +1,3 @@
music.m4a music.m4a
nested nested
nested2

View File

@ -1,2 +1,3 @@
.rw-rw-r-- 0 cassowary  1 Jan 12:34 music.m4a .rw-rw-r-- 0 cassowary  1 Jan 12:34 music.m4a
drwxrwxr-x - cassowary  1 Jan 12:34 nested drwxrwxr-x - cassowary  1 Jan 12:34 nested
drwxrwxr-x - cassowary  1 Jan 12:34 nested2

View File

@ -1 +1 @@
.rw-rw-r-- 0 cassowary  1 Jan 12:34 music.m4a drwxrwxr-x - cassowary  1 Jan 12:34 nested .rw-rw-r-- 0 cassowary  1 Jan 12:34 music.m4a drwxrwxr-x - cassowary  1 Jan 12:34 nested drwxrwxr-x - cassowary  1 Jan 12:34 nested2

View File

@ -1,5 +1,8 @@
.rw-rw-r-- 0 cassowary  1 Jan 12:34 music.m4a .rw-rw-r-- 0 cassowary  1 Jan 12:34 music.m4a
drwxrwxr-x - cassowary  1 Jan 12:34 nested drwxrwxr-x - cassowary  1 Jan 12:34 nested
drwxrwxr-x - cassowary  1 Jan 12:34 nested2
/testcases/git2/ignoreds/nested: /testcases/git2/ignoreds/nested:
.rw-rw-r-- 0 cassowary  1 Jan 12:34 funky chicken.m4a .rw-rw-r-- 0 cassowary  1 Jan 12:34 funky chicken.m4a
/testcases/git2/ignoreds/nested2:

View File

@ -1,4 +1,5 @@
drwxrwxr-x - cassowary  1 Jan 12:34 /testcases/git2/ignoreds drwxrwxr-x - cassowary  1 Jan 12:34 /testcases/git2/ignoreds
.rw-rw-r-- 0 cassowary  1 Jan 12:34 ├── music.m4a .rw-rw-r-- 0 cassowary  1 Jan 12:34 ├── music.m4a
drwxrwxr-x - cassowary  1 Jan 12:34 └── nested drwxrwxr-x - cassowary  1 Jan 12:34 ├── nested
.rw-rw-r-- 0 cassowary  1 Jan 12:34  └── funky chicken.m4a .rw-rw-r-- 0 cassowary  1 Jan 12:34 │ └── funky chicken.m4a
drwxrwxr-x - cassowary  1 Jan 12:34 └── nested2

View File

@ -1,4 +1,5 @@
/testcases/git2/ignoreds /testcases/git2/ignoreds
├── music.m4a ├── music.m4a
└── nested ├── nested
 └── funky chicken.m4a │ └── funky chicken.m4a
└── nested2

View File

@ -0,0 +1 @@
drwxrwxr-x - cassowary  1 Jan 12:34 -- /testcases/git2/ignoreds/nested2

View File

@ -1 +1 @@
.rw-rw-r-- 0 cassowary  1 Jan 12:34 -- another ignored file .rw-rw-r-- 0 cassowary  1 Jan 12:34 -I another ignored file

View File

@ -1,3 +1,4 @@
.rw-rw-r-- 0 cassowary  1 Jan 12:34 -N music.m4a .rw-rw-r-- 0 cassowary  1 Jan 12:34 -N music.m4a
.rw-rw-r-- 0 cassowary  1 Jan 12:34 -I music.mp3 .rw-rw-r-- 0 cassowary  1 Jan 12:34 -I music.mp3
drwxrwxr-x - cassowary  1 Jan 12:34 -N nested drwxrwxr-x - cassowary  1 Jan 12:34 -N nested
drwxrwxr-x - cassowary  1 Jan 12:34 -- nested2

View File

@ -5,6 +5,7 @@
.rw-rw-r-- 0 cassowary  1 Jan 12:34 -N music.m4a .rw-rw-r-- 0 cassowary  1 Jan 12:34 -N music.m4a
.rw-rw-r-- 0 cassowary  1 Jan 12:34 -I music.mp3 .rw-rw-r-- 0 cassowary  1 Jan 12:34 -I music.mp3
drwxrwxr-x - cassowary  1 Jan 12:34 -N nested drwxrwxr-x - cassowary  1 Jan 12:34 -N nested
drwxrwxr-x - cassowary  1 Jan 12:34 -- nested2
/testcases/git2/target: /testcases/git2/target:
.rw-rw-r-- 0 cassowary  1 Jan 12:34 -- another ignored file .rw-rw-r-- 0 cassowary  1 Jan 12:34 -I another ignored file

View File

@ -20,10 +20,14 @@
.rw-rw-r-- 0 cassowary  1 Jan 12:34 -N music.m4a .rw-rw-r-- 0 cassowary  1 Jan 12:34 -N music.m4a
.rw-rw-r-- 0 cassowary  1 Jan 12:34 -I music.mp3 .rw-rw-r-- 0 cassowary  1 Jan 12:34 -I music.mp3
drwxrwxr-x - cassowary  1 Jan 12:34 -N nested drwxrwxr-x - cassowary  1 Jan 12:34 -N nested
drwxrwxr-x - cassowary  1 Jan 12:34 -- nested2
/testcases/git2/ignoreds/nested: /testcases/git2/ignoreds/nested:
.rw-rw-r-- 0 cassowary  1 Jan 12:34 -I 70s grove.mp3 .rw-rw-r-- 0 cassowary  1 Jan 12:34 -I 70s grove.mp3
.rw-rw-r-- 0 cassowary  1 Jan 12:34 -N funky chicken.m4a .rw-rw-r-- 0 cassowary  1 Jan 12:34 -N funky chicken.m4a
/testcases/git2/ignoreds/nested2:
.rw-rw-r-- 0 cassowary  1 Jan 12:34 -I ievan polkka.mp3
/testcases/git2/target: /testcases/git2/target:
.rw-rw-r-- 0 cassowary  1 Jan 12:34 -- another ignored file .rw-rw-r-- 0 cassowary  1 Jan 12:34 -I another ignored file

View File

@ -18,6 +18,9 @@
/testcases/git2/ignoreds: /testcases/git2/ignoreds:
.rw-rw-r-- 0 cassowary  1 Jan 12:34 music.m4a .rw-rw-r-- 0 cassowary  1 Jan 12:34 music.m4a
drwxrwxr-x - cassowary  1 Jan 12:34 nested drwxrwxr-x - cassowary  1 Jan 12:34 nested
drwxrwxr-x - cassowary  1 Jan 12:34 nested2
/testcases/git2/ignoreds/nested: /testcases/git2/ignoreds/nested:
.rw-rw-r-- 0 cassowary  1 Jan 12:34 funky chicken.m4a .rw-rw-r-- 0 cassowary  1 Jan 12:34 funky chicken.m4a
/testcases/git2/ignoreds/nested2:

View File

@ -9,8 +9,10 @@
drwxrwxr-x - cassowary  1 Jan 12:34 -N ├── ignoreds drwxrwxr-x - cassowary  1 Jan 12:34 -N ├── ignoreds
.rw-rw-r-- 0 cassowary  1 Jan 12:34 -N │ ├── music.m4a .rw-rw-r-- 0 cassowary  1 Jan 12:34 -N │ ├── music.m4a
.rw-rw-r-- 0 cassowary  1 Jan 12:34 -I │ ├── music.mp3 .rw-rw-r-- 0 cassowary  1 Jan 12:34 -I │ ├── music.mp3
drwxrwxr-x - cassowary  1 Jan 12:34 -N │ └── nested drwxrwxr-x - cassowary  1 Jan 12:34 -N │ ├── nested
.rw-rw-r-- 0 cassowary  1 Jan 12:34 -I │ ├── 70s grove.mp3 .rw-rw-r-- 0 cassowary  1 Jan 12:34 -I │ │ ├── 70s grove.mp3
.rw-rw-r-- 0 cassowary  1 Jan 12:34 -N │ └── funky chicken.m4a .rw-rw-r-- 0 cassowary  1 Jan 12:34 -N │ │ └── funky chicken.m4a
drwxrwxr-x - cassowary  1 Jan 12:34 -- │ └── nested2
.rw-rw-r-- 0 cassowary  1 Jan 12:34 -I │ └── ievan polkka.mp3
drwxrwxr-x - cassowary  1 Jan 12:34 -I └── target drwxrwxr-x - cassowary  1 Jan 12:34 -I └── target
.rw-rw-r-- 0 cassowary  1 Jan 12:34 --  └── another ignored file .rw-rw-r-- 0 cassowary  1 Jan 12:34 -I  └── another ignored file

View File

@ -8,5 +8,6 @@
.rw-rw-r-- 0 cassowary  1 Jan 12:34 │ └── subfile .rw-rw-r-- 0 cassowary  1 Jan 12:34 │ └── subfile
drwxrwxr-x - cassowary  1 Jan 12:34 └── ignoreds drwxrwxr-x - cassowary  1 Jan 12:34 └── ignoreds
.rw-rw-r-- 0 cassowary  1 Jan 12:34  ├── music.m4a .rw-rw-r-- 0 cassowary  1 Jan 12:34  ├── music.m4a
drwxrwxr-x - cassowary  1 Jan 12:34  └── nested drwxrwxr-x - cassowary  1 Jan 12:34  ├── nested
.rw-rw-r-- 0 cassowary  1 Jan 12:34  └── funky chicken.m4a .rw-rw-r-- 0 cassowary  1 Jan 12:34  │ └── funky chicken.m4a
drwxrwxr-x - cassowary  1 Jan 12:34  └── nested2

View File

@ -8,5 +8,6 @@
│ └── subfile │ └── subfile
└── ignoreds └── ignoreds
 ├── music.m4a  ├── music.m4a
 └── nested  ├── nested
 └── funky chicken.m4a  │ └── funky chicken.m4a
 └── nested2