fix(pulls): respect diff.orderFile in diff file tree - #38566
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to make the pull-request diff file tree ordering respect Git’s diff.orderFile configuration by explicitly influencing git diff-tree output ordering, and adds a regression test to verify the behavior.
Changes:
- Updates
runGitDiffTreeto add-Oordering based on the configureddiff.orderFile. - Adds a new test that clones a fixture repo, sets
diff.orderFile, and asserts the resultingDiffTreefile order.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| services/gitdiff/git_diff_tree.go | Adds logic to apply diff.orderFile to git diff-tree ordering. |
| services/gitdiff/git_diff_tree_test.go | Adds a regression test ensuring diff.orderFile affects diff-tree ordering. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
services/gitdiff/git_diff_tree.go:68
git config --get diff.orderFilereturns the raw config value (no~expansion / path canonicalization). Passing that directly to-Ocan break whendiff.orderFileis configured as~/...or a relative path that Git would normally interpret as a pathname. Also, errors other than exit code 1 (missing key) are silently ignored, which can mask real config issues.
Consider using git config --path --get diff.orderFile and only ignoring exit code 1; for other errors, log and continue without -O.
if orderFile, _, err := gitcmd.NewCommand("config", "--get", "diff.orderFile").WithRepo(gitRepo).RunStdString(ctx); err == nil {
if orderFile = strings.TrimSpace(orderFile); orderFile != "" {
cmd.AddOptionFormat("-O%s", orderFile)
}
}
…ss per GetDiffTree call
| // Explicitly pass -O to ensure diff-tree ordering follows the configured global orderfile. | ||
| if orderFile, ok := getGlobalDiffOrderFile(ctx); ok { | ||
| cmd.AddOptionFormat("-O%s", orderFile) | ||
| } |
There was a problem hiding this comment.
You already have the global git config, why you need to override it again.
There was a problem hiding this comment.
For some reason, git diff-tree does not respect the orderFile, so here we are.
There was a problem hiding this comment.
For some reason, git diff-tree does not respect the orderFile, so here we are.
For what reason? Git's bug?
There was a problem hiding this comment.
From what I can tell by looking in the source code, seems to be a decision in Git not to look at orderFile for git diff-tree , but other commands like git diff do look oderFile up.
There was a problem hiding this comment.
man git-diff-tree
-O<orderfile>
Control the order in which files appear in the output.
This overrides the diff.orderFile configuration variable (see git-config(1)).
To cancel diff.orderFile, use -O/dev/null.
So, do you mean it is Git'd bug? Report to Git team?
There was a problem hiding this comment.
OK, I found the root problem now.
Indeed it is Git's problem: https://github.com/git/git/blame/master/builtin/diff-tree.c#L127 /* no "diff" UI options */ since 20 years ago.
It's fine to have a patch fix on Gitea side, while upstream (Git) should also have a proper fix, either make git-diff-tree respect the global config options, or fix the documents to avoid misleading users.
There was a problem hiding this comment.
The git manpage that is shared between diff and diff-tree could be improved to note this behavior: https://github.com/git/git/blame/master/Documentation/diff-options.adoc#L709
No description provided.