{"thread":{"id":"63799","subject":"[PATCH] test-lib: respect GIT_TEST_INSTALLED when querying default hash","startedAt":"2025-07-15T18:57:57Z","lastAt":"2025-07-15T21:39:16Z","messageCount":3,"participants":["Kyle Lippincott via GitGitGadget","Junio C Hamano","Justin Tobler"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"522027","messageId":"pull.2011.git.git.1752605874596.gitgitgadget@gmail.com","threadId":"63799","inReplyTo":null,"subject":"[PATCH] test-lib: respect GIT_TEST_INSTALLED when querying default hash","fromName":"Kyle Lippincott via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2025-07-15T18:57:54Z","receivedAt":"2025-07-15T18:57:57Z","isPatch":true,"sender":{"key":"spectral@google.com","avatar":"https://avatars.githubusercontent.com/u/6371650?v=4"},"body":"From: Kyle Lippincott <spectral@google.com>\n\n$GIT_TEST_INSTALLED can be set to use an \"installed\" git instead of the\none from $GIT_BUILD_DIR. This is used by my company's internal test\ninfrastructure, and not using $GIT_TEST_INSTALLED when querying the\ndefault hash meant that the tests were failing because the hash was\neffectively set to the empty string (since git didn't execute).\n\nIn the two places we attempt to detect/execute git itself prior to\noverriding everything and putting it in $PATH, use identical logic for\nidentifying the git binary to execute. This also has the effect of\nincluding the $X suffix when querying the default hash, but that's not\nstrictly necessary. You don't need to specify .exe when running a binary\non Windows, just when testing whether it exists or not.\n\nSigned-off-by: Kyle Lippincott <spectral@google.com>\n---\n    test-lib: respect GIT_TEST_INSTALLED when querying default hash\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2011%2Fspectral54%2Fdefault_hash_respect_git_test_installed-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2011/spectral54/default_hash_respect_git_test_installed-v1\nPull-Request: https://github.com/git/git/pull/2011\n\n t/test-lib.sh | 5 +++--\n 1 file changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex 6dc2022ee10..621cd31ae1d 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -134,7 +134,8 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n \n ################################################################\n # It appears that people try to run tests without building...\n-\"${GIT_TEST_INSTALLED:-$GIT_BUILD_DIR}/git$X\" >/dev/null\n+GIT_BINARY=\"${GIT_TEST_INSTALLED:-$GIT_BUILD_DIR}/git$X\"\n+\"$GIT_BINARY\" >/dev/null\n if test $? != 1\n then\n \tif test -n \"$GIT_TEST_INSTALLED\"\n@@ -536,7 +537,7 @@ export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME\n export GIT_COMMITTER_DATE GIT_AUTHOR_DATE\n export EDITOR\n \n-GIT_TEST_BUILTIN_HASH=$(\"$GIT_BUILD_DIR/git\" version --build-options | sed -ne 's/^default-hash: //p')\n+GIT_TEST_BUILTIN_HASH=$(\"$GIT_BINARY\" version --build-options | sed -ne 's/^default-hash: //p')\n GIT_DEFAULT_HASH=\"${GIT_TEST_DEFAULT_HASH:-$GIT_TEST_BUILTIN_HASH}\"\n export GIT_DEFAULT_HASH\n GIT_DEFAULT_REF_FORMAT=\"${GIT_TEST_DEFAULT_REF_FORMAT:-files}\"\n\nbase-commit: e9779f64349fbcc8d177d055208039877316e652\n-- \ngitgitgadget\n"},{"id":"522047","messageId":"xmqqv7ntf8ks.fsf@gitster.g","threadId":"63799","inReplyTo":"pull.2011.git.git.1752605874596.gitgitgadget@gmail.com","subject":"Re: [PATCH] test-lib: respect GIT_TEST_INSTALLED when querying default hash","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-07-15T21:27:47Z","receivedAt":"2025-07-15T21:27:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Kyle Lippincott via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n>  ################################################################\n>  # It appears that people try to run tests without building...\n> -\"${GIT_TEST_INSTALLED:-$GIT_BUILD_DIR}/git$X\" >/dev/null\n> +GIT_BINARY=\"${GIT_TEST_INSTALLED:-$GIT_BUILD_DIR}/git$X\"\n> +\"$GIT_BINARY\" >/dev/null\n>  if test $? != 1\n>  then\n>  \tif test -n \"$GIT_TEST_INSTALLED\"\n> @@ -536,7 +537,7 @@ export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME\n>  export GIT_COMMITTER_DATE GIT_AUTHOR_DATE\n>  export EDITOR\n>  \n> -GIT_TEST_BUILTIN_HASH=$(\"$GIT_BUILD_DIR/git\" version --build-options | sed -ne 's/^default-hash: //p')\n> +GIT_TEST_BUILTIN_HASH=$(\"$GIT_BINARY\" version --build-options | sed -ne 's/^default-hash: //p')\n\nVery nice.  I very much like the way this reuses what we detected earlier.\n\nThanks, will queue.\n\n>  GIT_DEFAULT_HASH=\"${GIT_TEST_DEFAULT_HASH:-$GIT_TEST_BUILTIN_HASH}\"\n>  export GIT_DEFAULT_HASH\n>  GIT_DEFAULT_REF_FORMAT=\"${GIT_TEST_DEFAULT_REF_FORMAT:-files}\"\n>\n> base-commit: e9779f64349fbcc8d177d055208039877316e652\n"},{"id":"522048","messageId":"gszrut3ruxmzelqjaeqfx767njz77yaxiq7fvuktezaobv72g6@ehlzm3c4kydm","threadId":"63799","inReplyTo":"pull.2011.git.git.1752605874596.gitgitgadget@gmail.com","subject":"Re: [PATCH] test-lib: respect GIT_TEST_INSTALLED when querying default hash","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2025-07-15T21:33:33Z","receivedAt":"2025-07-15T21:39:16Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"On 25/07/15 06:57PM, Kyle Lippincott via GitGitGadget wrote:\n> From: Kyle Lippincott <spectral@google.com>\n> \n> $GIT_TEST_INSTALLED can be set to use an \"installed\" git instead of the\n> one from $GIT_BUILD_DIR. This is used by my company's internal test\n> infrastructure, and not using $GIT_TEST_INSTALLED when querying the\n> default hash meant that the tests were failing because the hash was\n> effectively set to the empty string (since git didn't execute).\n> \n> In the two places we attempt to detect/execute git itself prior to\n> overriding everything and putting it in $PATH, use identical logic for\n> identifying the git binary to execute. This also has the effect of\n> including the $X suffix when querying the default hash, but that's not\n> strictly necessary. You don't need to specify .exe when running a binary\n> on Windows, just when testing whether it exists or not.\n\nThe second paragraph was a little difficult for me to parse, but I\nunderstand the change as the following:\n\nIn c79bb70a2e (Enable SHA-256 by default in breaking changes mode,\n2025-07-01), when building Git with `WITH_BREAKING_CHANGES` defined, the\ndefault object hash format is changed from SHA1 to SHA256. To select the\ncorrect hash used by `GIT_TEST_BUILTIN_HASH` during testing,\ngit-version(1) is executed with the `--build-options` flag to get the\ndefault hash the Git binary is built with.\n\nWhen running the Git testsuite with `GIT_TEST_INSTALLED` set, the Git\nbinary in `GIT_BUILD_DIR` is used to check for the default hash which is\nincorrect. Instead the binary at `GIT_TEST_INSTALLED` should be used.\n\n> Signed-off-by: Kyle Lippincott <spectral@google.com>\n> ---\n>     test-lib: respect GIT_TEST_INSTALLED when querying default hash\n> \n> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2011%2Fspectral54%2Fdefault_hash_respect_git_test_installed-v1\n> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2011/spectral54/default_hash_respect_git_test_installed-v1\n> Pull-Request: https://github.com/git/git/pull/2011\n> \n>  t/test-lib.sh | 5 +++--\n>  1 file changed, 3 insertions(+), 2 deletions(-)\n> \n> diff --git a/t/test-lib.sh b/t/test-lib.sh\n> index 6dc2022ee10..621cd31ae1d 100644\n> --- a/t/test-lib.sh\n> +++ b/t/test-lib.sh\n> @@ -134,7 +134,8 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\n>  \n>  ################################################################\n>  # It appears that people try to run tests without building...\n> -\"${GIT_TEST_INSTALLED:-$GIT_BUILD_DIR}/git$X\" >/dev/null\n> +GIT_BINARY=\"${GIT_TEST_INSTALLED:-$GIT_BUILD_DIR}/git$X\"\n> +\"$GIT_BINARY\" >/dev/null\n\nHere we store the Git binary we should be testing with so we can use it\nlater. Makes sense.\n\n>  if test $? != 1\n>  then\n>  \tif test -n \"$GIT_TEST_INSTALLED\"\n> @@ -536,7 +537,7 @@ export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME\n>  export GIT_COMMITTER_DATE GIT_AUTHOR_DATE\n>  export EDITOR\n>  \n> -GIT_TEST_BUILTIN_HASH=$(\"$GIT_BUILD_DIR/git\" version --build-options | sed -ne 's/^default-hash: //p')\n> +GIT_TEST_BUILTIN_HASH=$(\"$GIT_BINARY\" version --build-options | sed -ne 's/^default-hash: //p')\n\nNow we use the correct binary to check the default hash depending on how\nthe tests are executed. Looks good to me :)\n\n-Justin\n"}]}