Skip to content

Commit 949fe2c

Browse files
committed
Add a test to show what FIFO does to the dirwalk.
1 parent e6199a5 commit 949fe2c

File tree

3 files changed

+108
-1
lines changed

3 files changed

+108
-1
lines changed

gix-dir/tests/dir/walk.rs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,94 @@ use gix_dir::walk::EmissionMode::*;
1818
use gix_dir::walk::ForDeletionMode;
1919
use gix_ignore::Kind::*;
2020

21+
#[test]
22+
#[cfg(unix)]
23+
fn root_is_fifo() {
24+
let root = fixture_in("fifo", "top-level");
25+
26+
let err = try_collect(&root, None, |keep, ctx| {
27+
walk(
28+
&root,
29+
ctx,
30+
gix_dir::walk::Options {
31+
emit_ignored: Some(Matching),
32+
..options()
33+
},
34+
keep,
35+
)
36+
})
37+
.unwrap_err();
38+
assert!(
39+
matches!(err, gix_dir::walk::Error::WorktreeRootIsFile { .. }),
40+
"roots simply need to be directories to work"
41+
);
42+
}
43+
44+
#[test]
45+
#[cfg(unix)]
46+
fn one_top_level_fifo() {
47+
let root = fixture_in("fifo", "single-top-level-fifo");
48+
49+
let ((out, _root), entries) = collect(&root, None, |keep, ctx| {
50+
walk(
51+
&root,
52+
ctx,
53+
gix_dir::walk::Options {
54+
emit_pruned: false,
55+
..options()
56+
},
57+
keep,
58+
)
59+
});
60+
assert_eq!(
61+
out,
62+
walk::Outcome {
63+
read_dir_calls: 1,
64+
returned_entries: entries.len(),
65+
seen_entries: 2,
66+
}
67+
);
68+
69+
assert_eq!(entries, &[], "Non-files are simply pruned by default");
70+
}
71+
72+
#[test]
73+
#[cfg(unix)]
74+
fn fifo_in_traversal() {
75+
let root = fixture_in("fifo", "two-fifos-two-files");
76+
77+
let ((out, _root), entries) = collect(&root, None, |keep, ctx| {
78+
walk(
79+
&root,
80+
ctx,
81+
gix_dir::walk::Options {
82+
emit_pruned: true,
83+
..options()
84+
},
85+
keep,
86+
)
87+
});
88+
assert_eq!(
89+
out,
90+
walk::Outcome {
91+
read_dir_calls: 3,
92+
returned_entries: entries.len(),
93+
seen_entries: 5,
94+
}
95+
);
96+
97+
assert_eq!(
98+
entries,
99+
&[
100+
entry("dir-with-file/nested-file", Untracked, File),
101+
entry_nokind("dir/nested", Pruned),
102+
entry("file", Untracked, File),
103+
entry_nokind("top", Untracked),
104+
],
105+
"Non-files are simply pruned, and don't have a disk kind"
106+
);
107+
}
108+
21109
#[test]
22110
fn symlink_to_dir_can_be_excluded() -> crate::Result {
23111
let root = fixture_in("many-symlinks", "excluded-symlinks-to-dir");

gix-dir/tests/fixtures/fifo.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
set -eu -o pipefail
3+
4+
mkfifo top-level
5+
6+
git init single-top-level-fifo
7+
(cd single-top-level-fifo
8+
mkfifo top
9+
)
10+
11+
git init two-fifos-two-files
12+
(cd two-fifos-two-files
13+
mkdir dir dir-with-file
14+
touch file dir-with-file/nested-file
15+
16+
mkfifo top
17+
mkfifo dir/nested
18+
)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
many.tar
2-
many-symlinks.tar
2+
many-symlinks.tar
3+
fifo.tar

0 commit comments

Comments
 (0)