Git fork

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 749d6d166d (config: values of pathname type can be
prefixed with :(optional), 2025-09-28) and ccfcaf399f (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 <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Johannes Sixt and committed by
Junio C Hamano
91e6a645 ccfcaf39

+14 -5
+14 -5
t/t7500-commit-template-squash-signoff.sh
··· 33 33 ( 34 34 GIT_EDITOR="echo hello >" && 35 35 export GIT_EDITOR && 36 - test_must_fail git commit --template "$PWD"/notexist 36 + test_must_fail git commit --template "$(pwd)"/notexist 37 37 ) 38 38 ' 39 39 ··· 43 43 ( 44 44 GIT_EDITOR="echo hello >\"\$1\"" && 45 45 export GIT_EDITOR && 46 - git commit --template ":(optional)$PWD/notexist" 46 + git commit --template ":(optional)$(pwd)/notexist" 47 47 ) 48 48 ' 49 49 50 50 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 && 52 52 ( 53 53 GIT_EDITOR="echo hello >" && 54 54 export GIT_EDITOR && ··· 57 57 ' 58 58 59 59 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 && 61 61 GIT_EDITOR="echo hello >" git commit --allow-empty && 62 62 git cat-file commit HEAD | sed -e "1,/^$/d" >actual && 63 63 echo hello >expect && ··· 65 65 ' 66 66 67 67 # From now on we'll use a template file that exists. 68 - TEMPLATE="$PWD"/template 68 + TEMPLATE="$(pwd)"/template 69 69 70 70 test_expect_success 'unedited template should not commit' ' 71 71 echo "template line" >"$TEMPLATE" && ··· 97 97 git commit --allow-empty --template "$TEMPLATE" 98 98 ) && 99 99 commit_msg_is "template linecommit message" 100 + ' 101 + 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" 100 109 ' 101 110 102 111 test_expect_success '-t option should be short for --template' '