Skip to content

Commit

Permalink
parse_encrypt: Don't let e.g. "*.ext" match files in subdirs
Browse files Browse the repository at this point in the history
This matches the behavior before 3.4.0. Also silent errors from ls-files to
avoid warnings about e.g. directories that aren't readable (#521).
  • Loading branch information
erijo committed Feb 10, 2025
1 parent 5648f8b commit ac4195f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions test/test_encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def encrypt_targets(yadm_cmd, paths):
paths.work.join("globs dir/globs file2").write("globs file2")
expected.append("globs dir/globs file2")
paths.encrypt.write("globs*\n", mode="a")
paths.encrypt.write("globs*/globs*\n", mode="a")

# blank lines
paths.encrypt.write("\n \n\t\n", mode="a")
Expand Down
6 changes: 5 additions & 1 deletion test/test_unit_parse_encrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,11 @@ def create_test_encrypt_data(paths):
edata += "*card1\n" # matches same file as the one above
paths.work.join("wildcard1").write("", ensure=True)
paths.work.join("wildcard2").write("", ensure=True)
paths.work.join("subdir/wildcard1").write("", ensure=True)
expected.add("wildcard1")
expected.add("wildcard2")

edata += "dirwild*\n"
edata += "dirwild*/file*\n"
paths.work.join("dirwildcard/file1").write("", ensure=True)
paths.work.join("dirwildcard/file2").write("", ensure=True)
expected.add("dirwildcard/file1")
Expand All @@ -125,6 +126,9 @@ def create_test_encrypt_data(paths):
expected.add("ex ex/file4")
expected.add("ex ex/file6.text")

paths.work.join("dirwildcard/file7.ex").write("", ensure=True)
expected.add("dirwildcard/file7.ex")

# double star
edata += "doublestar/**/file*\n"
edata += "!**/file3\n"
Expand Down
7 changes: 5 additions & 2 deletions yadm
Original file line number Diff line number Diff line change
Expand Up @@ -1932,7 +1932,7 @@ function parse_encrypt() {
# Ignore comments
;;
!*)
exclude+=("--exclude=${pattern:1}")
exclude+=("--exclude=/${pattern:1}")
;;
*)
if ! [[ $pattern =~ ^[[:blank:]]*$ ]]; then
Expand All @@ -1945,7 +1945,10 @@ function parse_encrypt() {
if [[ ${#include} -gt 0 ]]; then
while IFS= read -r filename; do
ENCRYPT_INCLUDE_FILES+=("${filename%/}")
done <<<"$("$GIT_PROGRAM" ls-files --others "${exclude[@]}" -- "${include[@]}")"
done <<<"$(
"$GIT_PROGRAM" --glob-pathspecs ls-files --others \
"${exclude[@]}" -- "${include[@]}" 2>/dev/null
)"
fi
}

Expand Down

0 comments on commit ac4195f

Please sign in to comment.