]> Nutra Git (v1) - gamesguru/git-remote-gcrypt.git/commitdiff
show all files (not just top-level dirs) in clean
authorShane Jaroch <chown_tee@proton.me>
Fri, 9 Jan 2026 17:19:48 +0000 (12:19 -0500)
committerShane Jaroch <chown_tee@proton.me>
Fri, 9 Jan 2026 17:23:17 +0000 (12:23 -0500)
git-remote-gcrypt
tests/test-clean-command.sh

index 6768ab34d2f5efeb1607a3f29587603fbe150b73..624997bce9473b98a7e2e3f8a8f9fd065c23f073 100755 (executable)
@@ -1390,7 +1390,7 @@ cmd_clean()
                echo_info "WARNING: sftp clean support is experimental and may cause data loss."
                remote_files=$(curl -s -S -k "$URL/" 2>/dev/null | grep -vE '^\.$|^\.\.$' || :)
        else
-               remote_files=$(git ls-tree --name-only "$Gref" 2>/dev/null || :)
+               remote_files=$(git ls-tree -r --name-only "$Gref" 2>/dev/null || :)
        fi
 
        if isnull "$remote_files"; then
@@ -1411,11 +1411,14 @@ cmd_clean()
        
        # Find files to delete
        bad_files=""
+       OIFS="$IFS"
+       IFS="$Newline"
        for f in $remote_files; do
                if isnull "$valid_files" || ! xfeed "$valid_files" grep -qxF "$f"; then
                        bad_files="$bad_files$Newline$f"
                fi
        done
+       IFS="$OIFS"
        bad_files="${bad_files#"$Newline"}"
        
        if isnull "$bad_files"; then
index 51448c3a4742ac8c98eb417eb075c7920aa75d7c..11dc50b33eefe3d9af18ae85c68df256bfa98198 100755 (executable)
@@ -76,12 +76,30 @@ $GIT config gpg.program "${GNUPGHOME}/gpg"
 $GIT config gcrypt.participants "test@test.com"
 
 # Add multiple unencrypted files
+# Add multiple unencrypted files including nested ones
 echo "SECRET=abc" >"$tempdir/secret1.txt"
 echo "PASSWORD=xyz" >"$tempdir/secret2.txt"
+# Nested file
+mkdir -p "$tempdir/subdir"
+echo "NESTED=123" >"$tempdir/subdir/nested.txt"
+
+echo "SPACE=789" >"$tempdir/Has Space.txt"
+
 BLOB1=$($GIT hash-object -w "$tempdir/secret1.txt")
 BLOB2=$($GIT hash-object -w "$tempdir/secret2.txt")
-TREE=$(echo -e "100644 blob $BLOB1\tsecret1.txt\n100644 blob $BLOB2\tsecret2.txt" | $GIT mktree)
-COMMIT=$(echo "Dirty commit" | $GIT commit-tree "$TREE")
+BLOB3=$($GIT hash-object -w "$tempdir/subdir/nested.txt")
+BLOB4=$($GIT hash-object -w "$tempdir/Has Space.txt")
+
+# Create root tree using index
+export GIT_INDEX_FILE=index.dirty
+$GIT update-index --add --cacheinfo 100644 "$BLOB1" "secret1.txt"
+$GIT update-index --add --cacheinfo 100644 "$BLOB2" "secret2.txt"
+$GIT update-index --add --cacheinfo 100644 "$BLOB3" "subdir/nested.txt"
+$GIT update-index --add --cacheinfo 100644 "$BLOB4" "Has Space.txt"
+TREE=$($GIT write-tree)
+rm index.dirty
+
+COMMIT=$(echo "Dirty commit with nested files" | $GIT commit-tree "$TREE")
 $GIT update-ref refs/heads/master "$COMMIT"
 
 print_info "Created dirty remote with 2 unencrypted files"
@@ -240,6 +258,8 @@ output=$("$SCRIPT_DIR/git-remote-gcrypt" clean --init "gcrypt::$tempdir/remote.g
 assert_grep "WARNING: No gcrypt manifest found, but --init specified" "$output" "--init warns about missing manifest"
 assert_grep "Found the following files to remove" "$output" "--init scan found files"
 assert_grep "secret1.txt" "$output" "--init found secret1.txt"
+assert_grep "subdir/nested.txt" "$output" "--init found nested file in subdir"
+assert_grep "Has Space.txt" "$output" "--init found file with spaces"
 
 # 3. Clean with --init --force should remove files
 "$SCRIPT_DIR/git-remote-gcrypt" clean --init --force "gcrypt::$tempdir/remote.git" >/dev/null 2>&1