Skip to content

Commit 91e6a64

Browse files
j6tgitster
authored andcommitted
t7500: fix tests with absolute path following ":(optional)" on Windows
On Windows, the MSYS layer translates absolute path names generated by a shell script from the POSIX style /c/dir/file to the Windows style C:/dir/file form that is understood by git.exe. This happens only when the absolute path stands on its own as a program argument or a value of an environment variable. The earlier commits 749d6d1 (config: values of pathname type can be prefixed with :(optional), 2025-09-28) and ccfcaf3 (parseopt: values of pathname type can be prefixed with :(optional), 2025-09-28) added test cases where ":(optional)" is inserted before an absolute path. $PWD is used to construct the absolute paths, which gives the POSIX form, and the result is ":(optional)/c/dir/template". Such command line arguments are no longer recognized as absolute paths and do not undergo translation. Existing test cases that expect that the specified file does not exist are not incorrect (after all, git.exe will not find /c/dir/template). Yet, they are conceptually incorrect. That the use of $PWD is erroneous is revealed by a test case that expects that the optional file exists. Since no such test case is present, add one. Use "$(pwd)" to generate the absolute paths, so that the command line arguments become ":(optional)C:/dir/template". Signed-off-by: Johannes Sixt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ccfcaf3 commit 91e6a64

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

t/t7500-commit-template-squash-signoff.sh

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ test_expect_success 'nonexistent template file should return error' '
3333
(
3434
GIT_EDITOR="echo hello >" &&
3535
export GIT_EDITOR &&
36-
test_must_fail git commit --template "$PWD"/notexist
36+
test_must_fail git commit --template "$(pwd)"/notexist
3737
)
3838
'
3939

@@ -43,12 +43,12 @@ test_expect_success 'nonexistent optional template file on command line' '
4343
(
4444
GIT_EDITOR="echo hello >\"\$1\"" &&
4545
export GIT_EDITOR &&
46-
git commit --template ":(optional)$PWD/notexist"
46+
git commit --template ":(optional)$(pwd)/notexist"
4747
)
4848
'
4949

5050
test_expect_success 'nonexistent template file in config should return error' '
51-
test_config commit.template "$PWD"/notexist &&
51+
test_config commit.template "$(pwd)"/notexist &&
5252
(
5353
GIT_EDITOR="echo hello >" &&
5454
export GIT_EDITOR &&
@@ -57,15 +57,15 @@ test_expect_success 'nonexistent template file in config should return error' '
5757
'
5858

5959
test_expect_success 'nonexistent optional template file in config' '
60-
test_config commit.template ":(optional)$PWD"/notexist &&
60+
test_config commit.template ":(optional)$(pwd)"/notexist &&
6161
GIT_EDITOR="echo hello >" git commit --allow-empty &&
6262
git cat-file commit HEAD | sed -e "1,/^$/d" >actual &&
6363
echo hello >expect &&
6464
test_cmp expect actual
6565
'
6666

6767
# From now on we'll use a template file that exists.
68-
TEMPLATE="$PWD"/template
68+
TEMPLATE="$(pwd)"/template
6969

7070
test_expect_success 'unedited template should not commit' '
7171
echo "template line" >"$TEMPLATE" &&
@@ -99,6 +99,15 @@ test_expect_success 'adding real content to a template should commit' '
9999
commit_msg_is "template linecommit message"
100100
'
101101

102+
test_expect_success 'existent template marked optional should commit' '
103+
echo "existent template" >"$TEMPLATE" &&
104+
(
105+
test_set_editor "$TEST_DIRECTORY"/t7500/add-content &&
106+
git commit --allow-empty --template ":(optional)$TEMPLATE"
107+
) &&
108+
commit_msg_is "existent templatecommit message"
109+
'
110+
102111
test_expect_success '-t option should be short for --template' '
103112
echo "short template" > "$TEMPLATE" &&
104113
echo "new content" >> foo &&

0 commit comments

Comments
 (0)