From dd54a44f449ecec953c359973247c7ccd167caf6 Mon Sep 17 00:00:00 2001 From: Christian Schilling Date: Mon, 8 May 2023 16:35:38 +0200 Subject: [PATCH] Make ::path match directories as well as files 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 --- docs/src/reference/filters.md | 4 +- josh-core/src/filter/mod.rs | 6 +-- tests/filter/workspace_single_file.t | 61 ++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 7 deletions(-) diff --git a/docs/src/reference/filters.md b/docs/src/reference/filters.md index 37227b75c..e7dca5a50 100644 --- a/docs/src/reference/filters.md +++ b/docs/src/reference/filters.md @@ -81,8 +81,8 @@ allowed. ### Match directories **`::X/`** All matching subdirectories in the input root -### Match files **`::X`** -All matching files in the input root +### Match files or directories **`::X`** +All matching files or directories in the input root ### Match nested directories **`::**/X/`** All subdirectories matching the pattern in arbitrarily deep subdirectories of the input diff --git a/josh-core/src/filter/mod.rs b/josh-core/src/filter/mod.rs index 3047f07fb..249615e5e 100644 --- a/josh-core/src/filter/mod.rs +++ b/josh-core/src/filter/mod.rs @@ -759,11 +759,7 @@ fn apply2<'a>( .get_path(path) .map(|x| (x.id(), x.filemode())) .unwrap_or((git2::Oid::zero(), 0o0100644)); - if repo.find_blob(file).is_ok() { - tree::insert(repo, &tree::empty(repo), path, file, mode) - } else { - Ok(tree::empty(repo)) - } + tree::insert(repo, &tree::empty(repo), path, file, mode) } Op::Subdir(path) => { diff --git a/tests/filter/workspace_single_file.t b/tests/filter/workspace_single_file.t index 9809cabe9..4fbc61615 100644 --- a/tests/filter/workspace_single_file.t +++ b/tests/filter/workspace_single_file.t @@ -28,6 +28,15 @@ $ git add ws $ git commit -m "add ws" 1> /dev/null + $ mkdir ws2 + $ cat > ws2/workspace.josh < :/sub1::file1 + > :/sub1::file2 + > ::sub2/subsub + > EOF + $ git add ws2 + $ git commit -m "add ws2" 1> /dev/null + $ josh-filter -s :workspace=ws master --update refs/josh/master [1] :/sub1 [1] :/subsub @@ -70,3 +79,55 @@ `-- workspace.josh 2 directories, 4 files + + $ josh-filter -s :workspace=ws2 master --update refs/josh/master + [1] :/sub1 + [1] :/subsub + [1] ::file1 + [1] ::file2 + [1] :[ + ::file1 + ::file2 + ] + [1] :prefix=sub2 + [1] :prefix=subsub + [2] :/sub2 + [2] ::sub2/subsub + [2] :[ + :/sub1:[ + ::file1 + ::file2 + ] + ::sub2/subsub + ] + [2] :[ + :/sub1:[ + ::file1 + ::file2 + ] + ::sub2/subsub/ + ] + [2] :workspace=ws + [2] :workspace=ws2 + + $ git log --graph --pretty=%s refs/josh/master + * add ws2 + * add file2 + * add file1 + + $ git checkout refs/josh/master 2> /dev/null + $ git ls-tree HEAD + 100644 blob a024003ee1acc6bf70318a46e7b6df651b9dc246\tfile1 (esc) + 100755 blob a024003ee1acc6bf70318a46e7b6df651b9dc246\tfile2 (esc) + 040000 tree 81b2a24c53f9090c6f6a23176a2a5660e6f48317\tsub2 (esc) + 100644 blob f7863ebb4c21391857fe5d27bc381553a2056223\tworkspace.josh (esc) + $ tree + . + |-- file1 + |-- file2 + |-- sub2 + | `-- subsub + | `-- file2 + `-- workspace.josh + + 2 directories, 4 files