Skip to content

Commit 568cabb

Browse files
SyntevoAlexgitster
authored andcommitted
t: fix quotes tests for --pathspec-from-file
While working on the next patch, I also noticed that quotes testing via `"\"file\\101.t\""` was somewhat incorrect: I escaped `\` one time while I had to escape it two times! Tests still worked due to `"` being preserved which in turn prevented pathspec from matching files. Fix this by using here-doc instead. Signed-off-by: Alexandr Miloslavskiy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d0654dc commit 568cabb

5 files changed

+45
-11
lines changed

t/t2026-checkout-pathspec-file.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ test_expect_success 'CRLF delimiters' '
109109
test_expect_success 'quotes' '
110110
restore_checkpoint &&
111111
112-
printf "\"file\\101.t\"" | git checkout --pathspec-from-file=- HEAD^1 &&
112+
cat >list <<-\EOF &&
113+
"file\101.t"
114+
EOF
115+
116+
git checkout --pathspec-from-file=list HEAD^1 &&
113117
114118
cat >expect <<-\EOF &&
115119
M fileA.t
@@ -120,7 +124,10 @@ test_expect_success 'quotes' '
120124
test_expect_success 'quotes not compatible with --pathspec-file-nul' '
121125
restore_checkpoint &&
122126
123-
printf "\"file\\101.t\"" >list &&
127+
cat >list <<-\EOF &&
128+
"file\101.t"
129+
EOF
130+
124131
test_must_fail git checkout --pathspec-from-file=list --pathspec-file-nul HEAD^1
125132
'
126133

t/t2072-restore-pathspec-file.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ test_expect_success 'CRLF delimiters' '
109109
test_expect_success 'quotes' '
110110
restore_checkpoint &&
111111
112-
printf "\"file\\101.t\"" | git restore --pathspec-from-file=- --source=HEAD^1 &&
112+
cat >list <<-\EOF &&
113+
"file\101.t"
114+
EOF
115+
116+
git restore --pathspec-from-file=list --source=HEAD^1 &&
113117
114118
cat >expect <<-\EOF &&
115119
M fileA.t
@@ -120,7 +124,10 @@ test_expect_success 'quotes' '
120124
test_expect_success 'quotes not compatible with --pathspec-file-nul' '
121125
restore_checkpoint &&
122126
123-
printf "\"file\\101.t\"" >list &&
127+
cat >list <<-\EOF &&
128+
"file\101.t"
129+
EOF
130+
124131
test_must_fail git restore --pathspec-from-file=list --pathspec-file-nul --source=HEAD^1
125132
'
126133

t/t3704-add-pathspec-file.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ test_expect_success 'CRLF delimiters' '
9797
test_expect_success 'quotes' '
9898
restore_checkpoint &&
9999
100-
printf "\"file\\101.t\"" | git add --pathspec-from-file=- &&
100+
cat >list <<-\EOF &&
101+
"file\101.t"
102+
EOF
103+
104+
git add --pathspec-from-file=list &&
101105
102106
cat >expect <<-\EOF &&
103107
A fileA.t
@@ -108,7 +112,10 @@ test_expect_success 'quotes' '
108112
test_expect_success 'quotes not compatible with --pathspec-file-nul' '
109113
restore_checkpoint &&
110114
111-
printf "\"file\\101.t\"" >list &&
115+
cat >list <<-\EOF &&
116+
"file\101.t"
117+
EOF
118+
112119
test_must_fail git add --pathspec-from-file=list --pathspec-file-nul
113120
'
114121

t/t7107-reset-pathspec-file.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,12 @@ test_expect_success 'CRLF delimiters' '
105105
test_expect_success 'quotes' '
106106
restore_checkpoint &&
107107
108+
cat >list <<-\EOF &&
109+
"file\101.t"
110+
EOF
111+
108112
git rm fileA.t &&
109-
printf "\"file\\101.t\"" | git reset --pathspec-from-file=- &&
113+
git reset --pathspec-from-file=list &&
110114
111115
cat >expect <<-\EOF &&
112116
D fileA.t
@@ -117,8 +121,10 @@ test_expect_success 'quotes' '
117121
test_expect_success 'quotes not compatible with --pathspec-file-nul' '
118122
restore_checkpoint &&
119123
120-
git rm fileA.t &&
121-
printf "\"file\\101.t\"" >list &&
124+
cat >list <<-\EOF &&
125+
"file\101.t"
126+
EOF
127+
122128
# Note: "git reset" has not yet learned to fail on wrong pathspecs
123129
git reset --pathspec-from-file=list --pathspec-file-nul &&
124130

t/t7526-commit-pathspec-file.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ test_expect_success 'CRLF delimiters' '
100100
test_expect_success 'quotes' '
101101
restore_checkpoint &&
102102
103-
printf "\"file\\101.t\"" | git commit --pathspec-from-file=- -m "Commit" &&
103+
cat >list <<-\EOF &&
104+
"file\101.t"
105+
EOF
106+
107+
git commit --pathspec-from-file=list -m "Commit" &&
104108
105109
cat >expect <<-\EOF &&
106110
A fileA.t
@@ -111,7 +115,10 @@ test_expect_success 'quotes' '
111115
test_expect_success 'quotes not compatible with --pathspec-file-nul' '
112116
restore_checkpoint &&
113117
114-
printf "\"file\\101.t\"" >list &&
118+
cat >list <<-\EOF &&
119+
"file\101.t"
120+
EOF
121+
115122
test_must_fail git commit --pathspec-from-file=list --pathspec-file-nul -m "Commit"
116123
'
117124

0 commit comments

Comments
 (0)