Skip to content

fix(pulls): respect diff.orderFile in diff file tree - #38566

Merged
bircni merged 8 commits into
go-gitea:mainfrom
eliroca:git-diff-tree
Jul 22, 2026
Merged

fix(pulls): respect diff.orderFile in diff file tree#38566
bircni merged 8 commits into
go-gitea:mainfrom
eliroca:git-diff-tree

Conversation

@eliroca

@eliroca eliroca commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI review requested due to automatic review settings July 21, 2026 22:56
@GiteaBot GiteaBot added lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jul 21, 2026
@eliroca
eliroca marked this pull request as draft July 21, 2026 22:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 runGitDiffTree to add -O ordering based on the configured diff.orderFile.
  • Adds a new test that clones a fixture repo, sets diff.orderFile, and asserts the resulting DiffTree file 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.

Comment thread services/gitdiff/git_diff_tree.go Outdated
Comment thread services/gitdiff/git_diff_tree_test.go Outdated
Copilot AI review requested due to automatic review settings July 21, 2026 23:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.orderFile returns the raw config value (no ~ expansion / path canonicalization). Passing that directly to -O can break when diff.orderFile is 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)
		}
	}

Copilot AI review requested due to automatic review settings July 21, 2026 23:17
@eliroca
eliroca marked this pull request as ready for review July 21, 2026 23:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread services/gitdiff/git_diff_tree.go Outdated
Comment thread services/gitdiff/git_diff_tree_test.go Outdated
Copilot AI review requested due to automatic review settings July 21, 2026 23:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread services/gitdiff/git_diff_tree.go Outdated
Comment thread services/gitdiff/git_diff_tree.go Outdated
// Explicitly pass -O to ensure diff-tree ordering follows the configured global orderfile.
if orderFile, ok := getGlobalDiffOrderFile(ctx); ok {
cmd.AddOptionFormat("-O%s", orderFile)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You already have the global git config, why you need to override it again.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason, git diff-tree does not respect the orderFile, so here we are.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason, git diff-tree does not respect the orderFile, so here we are.

For what reason? Git's bug?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@wxiaoguang wxiaoguang Jul 22, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@wxiaoguang
wxiaoguang marked this pull request as draft July 21, 2026 23:39
Copilot AI review requested due to automatic review settings July 21, 2026 23:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread services/gitdiff/git_diff_tree.go Outdated
Copilot AI review requested due to automatic review settings July 22, 2026 01:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings July 22, 2026 02:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@wxiaoguang
wxiaoguang marked this pull request as ready for review July 22, 2026 02:01
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jul 22, 2026
Copilot AI review requested due to automatic review settings July 22, 2026 04:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@wxiaoguang wxiaoguang added this to the 28.0.0 milestone Jul 22, 2026
@bircni bircni added the backport/v1.27 This PR should be backported to Gitea 1.27 label Jul 22, 2026
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jul 22, 2026
Copilot AI review requested due to automatic review settings July 22, 2026 14:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review is ineligible. To be eligible to request a review, you need a paid Copilot license, or your organization must enable Copilot code review.

@bircni
bircni enabled auto-merge (squash) July 22, 2026 14:54
@bircni bircni added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Jul 22, 2026
@bircni
bircni merged commit c8df67c into go-gitea:main Jul 22, 2026
22 checks passed
@GiteaBot GiteaBot added backport/done All backports for this PR have been created and removed reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. labels Jul 22, 2026
silverwind pushed a commit that referenced this pull request Jul 22, 2026
Backport #38566 by @eliroca

Co-authored-by: Elisei Roca <eroca@suse.de>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
@eliroca
eliroca deleted the git-diff-tree branch July 24, 2026 21:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/done All backports for this PR have been created backport/v1.27 This PR should be backported to Gitea 1.27 lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants