Skip to content

Commit cb041ad

Browse files
Make ::path match directories as well as files (#1204)
Previously `::path/` only matched directories while `::path` only matched files. With this change `::path` matches both, while keeping the behaviour of `::path/` as is. This is in line on how things are handled in git's gitignore pattern syntax. Change: match-dirs-and-files
1 parent 8333098 commit cb041ad

File tree

4 files changed

+67
-8
lines changed

4 files changed

+67
-8
lines changed

docs/src/reference/filters.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ allowed.
8181
### Match directories **`::X/`**
8282
All matching subdirectories in the input root
8383

84-
### Match files **`::X`**
85-
All matching files in the input root
84+
### Match files or directories **`::X`**
85+
All matching files or directories in the input root
8686

8787
### Match nested directories **`::**/X/`**
8888
All subdirectories matching the pattern in arbitrarily deep subdirectories of the input

josh-core/src/filter/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -759,11 +759,7 @@ fn apply2<'a>(
759759
.get_path(path)
760760
.map(|x| (x.id(), x.filemode()))
761761
.unwrap_or((git2::Oid::zero(), 0o0100644));
762-
if repo.find_blob(file).is_ok() {
763-
tree::insert(repo, &tree::empty(repo), path, file, mode)
764-
} else {
765-
Ok(tree::empty(repo))
766-
}
762+
tree::insert(repo, &tree::empty(repo), path, file, mode)
767763
}
768764

769765
Op::Subdir(path) => {

tests/filter/workspace_single_file.t

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@
2828
$ git add ws
2929
$ git commit -m "add ws" 1> /dev/null
3030

31+
$ mkdir ws2
32+
$ cat > ws2/workspace.josh <<EOF
33+
> :/sub1::file1
34+
> :/sub1::file2
35+
> ::sub2/subsub
36+
> EOF
37+
$ git add ws2
38+
$ git commit -m "add ws2" 1> /dev/null
39+
3140
$ josh-filter -s :workspace=ws master --update refs/josh/master
3241
[1] :/sub1
3342
[1] :/subsub
@@ -70,3 +79,55 @@
7079
`-- workspace.josh
7180

7281
2 directories, 4 files
82+
83+
$ josh-filter -s :workspace=ws2 master --update refs/josh/master
84+
[1] :/sub1
85+
[1] :/subsub
86+
[1] ::file1
87+
[1] ::file2
88+
[1] :[
89+
::file1
90+
::file2
91+
]
92+
[1] :prefix=sub2
93+
[1] :prefix=subsub
94+
[2] :/sub2
95+
[2] ::sub2/subsub
96+
[2] :[
97+
:/sub1:[
98+
::file1
99+
::file2
100+
]
101+
::sub2/subsub
102+
]
103+
[2] :[
104+
:/sub1:[
105+
::file1
106+
::file2
107+
]
108+
::sub2/subsub/
109+
]
110+
[2] :workspace=ws
111+
[2] :workspace=ws2
112+
113+
$ git log --graph --pretty=%s refs/josh/master
114+
* add ws2
115+
* add file2
116+
* add file1
117+
118+
$ git checkout refs/josh/master 2> /dev/null
119+
$ git ls-tree HEAD
120+
100644 blob a024003ee1acc6bf70318a46e7b6df651b9dc246\tfile1 (esc)
121+
100755 blob a024003ee1acc6bf70318a46e7b6df651b9dc246\tfile2 (esc)
122+
040000 tree 81b2a24c53f9090c6f6a23176a2a5660e6f48317\tsub2 (esc)
123+
100644 blob f7863ebb4c21391857fe5d27bc381553a2056223\tworkspace.josh (esc)
124+
$ tree
125+
.
126+
|-- file1
127+
|-- file2
128+
|-- sub2
129+
| `-- subsub
130+
| `-- file2
131+
`-- workspace.josh
132+
133+
2 directories, 4 files

tests/proxy/push_stacked.t

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ Make sure all temporary namespace got removed
224224
| | `-- c67dccc160a868cefdab0bd9d7141b7276c4f3
225225
| |-- 49
226226
| | `-- 03654ec80c5cff86ab37a0b9d7bcf8332e8c54
227+
| |-- 4b
228+
| | `-- 825dc642cb6eb9a060e54bf8d69288fbee4904
227229
| |-- 57
228230
| | `-- a39cc050b1493cf6313822f0de3cee3ca4f39a
229231
| |-- 6b
@@ -249,7 +251,7 @@ Make sure all temporary namespace got removed
249251
|-- namespaces
250252
`-- tags
251253

252-
55 directories, 43 files
254+
56 directories, 44 files
253255

254256
$ cat ${TESTTMP}/josh-proxy.out
255257
$ cat ${TESTTMP}/josh-proxy.out | grep REPO_UPDATE

0 commit comments

Comments
 (0)