test: fix TestGitDiffTreeRespectsDiffOrderFile on git older than 2.46 (#40492)

`TestGitDiffTreeRespectsDiffOrderFile` fails on git older than 2.46,
such as the 2.43 that Ubuntu 24.04 ships, even though Gitea supports git
2.34 and newer. Its `GlobalDiffOrderFile` subtest sets and removes the
global `diff.orderFile` with `git config set` and `git config unset`,
which were added in git 2.46, so older git stops it at the first call
with `exit status 129 - usage: git config [<options>]`.

The test now uses `git config --global` and `git config --global
--unset`, the classic syntax that `modules/git/config.go` also uses.
With git 2.34.1 and 2.43.0 the test failed before and passes now; git
2.56.1 passes either way.

Follow-up to https://github.com/go-gitea/gitea/pull/38566

Assisted-by: Hermes Agent:claude-opus-5-5
This commit is contained in:
Zhaowei Gu
2026-11-23 12:31:39 +00:00
committed by GitHub
parent c04f64824b
commit 8b1b80bbf2

View File

@@ -201,11 +201,11 @@ func TestGitDiffTreeRespectsDiffOrderFile(t *testing.T) {
err = os.WriteFile(diffOrderFilePath, []byte("README.md\nLICENSE\n"), 0o644)
require.NoError(t, err)
_, _, err = gitcmd.NewCommand("config", "set", "--global").AddDynamicArguments("diff.orderFile", diffOrderFilePath).RunStdString(t.Context())
_, _, err = gitcmd.NewCommand("config", "--global").AddDynamicArguments("diff.orderFile", diffOrderFilePath).RunStdString(t.Context())
require.NoError(t, err)
require.NoError(t, git.InitFull())
defer func() {
_, _, err = gitcmd.NewCommand("config", "unset", "--global").AddDynamicArguments("diff.orderFile").RunStdString(t.Context())
_, _, err = gitcmd.NewCommand("config", "--global", "--unset").AddDynamicArguments("diff.orderFile").RunStdString(t.Context())
require.NoError(t, err)
require.NoError(t, git.InitFull())
}()