Skip to content

fix(git): list affected files NUL-separated so special names are not quoted - #40324

Closed
lunny wants to merge 5 commits into
go-gitea:mainfrom
lunny:fix-affected-files-quoting
Closed

lunny wants to merge 5 commits into
go-gitea:mainfrom
lunny:fix-affected-files-quoting

Conversation

@lunny

@lunny lunny commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

GetAffectedFiles parsed git diff --name-only line output, where git C-quotes paths containing characters such as " or non-ASCII bytes. The quoted string never matched protected file patterns, so pushes and merges touching such files bypassed them.

It now reuses GetFilesChangedBetween (NUL-separated diff-tree) and no longer trims whitespace from real file names. As diff-tree does no rename detection, a rename now reports both the old and the new path, so protected patterns also match the old path. The PR diff view marks a renamed file as protected by its old path too.

…quoted

GetAffectedFiles parsed `git diff --name-only` line output, where git
C-quotes paths containing characters such as `"` or non-ASCII bytes.
The quoted string never matched protected file patterns, so pushes and
merges touching such files bypassed them. Use -z and split on NUL, and
stop trimming whitespace from real file names.

Assisted-by: Codet:claude
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Nov 10, 2026
@lunny lunny added the backport/v28 This PR should be backported to Gitea 28 label Nov 10, 2026
@lunny
lunny requested a balanced review from Copilot November 10, 2026 21:56

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 insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@GiteaBot GiteaBot added the backport/conflict-free Would cherry-pick onto the latest release branch without conflicts label Nov 10, 2026
Comment thread modules/git/diff.go Outdated
// Run `git diff --name-only` to get the names of the changed files
cmd := gitcmd.NewCommand("diff", "--name-only").AddDynamicArguments(oldCommitID, newCommitID)
// "-z" keeps paths raw, otherwise git quotes special characters and they can no longer match path patterns
cmd := gitcmd.NewCommand("diff", "--name-only", "-z").AddDynamicArguments(oldCommitID, newCommitID)

@wxiaoguang wxiaoguang Nov 11, 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.

There are already a lot of "diff --name-only" commands.

For example: why not refactor and reuse GetFilesChangedBetween?

@GiteaBot GiteaBot removed the backport/conflict-free Would cherry-pick onto the latest release branch without conflicts label Nov 11, 2026
@lunny lunny changed the title fix(git): read affected files NUL-separated so special names are not quoted fix(git): list affected files NUL-separated so special names are not quoted Nov 11, 2026
}

// GetFilesChangedBetweenWithEnv is like GetFilesChangedBetween but runs git with extra env (e.g. a pre-receive quarantine)
func (repo *Repository) GetFilesChangedBetweenWithEnv(ctx context.Context, base, head string, env []string) ([]string, error) {

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.

I don't think it is right to keep adding new special functions into "*Repository".

And I don't think it is right to expose "env" in a public function to callers.

-> refactor(git): parse git stdout correctly - #40326

@wxiaoguang

wxiaoguang commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Everything should have been addressed in #40326

The new test is not necessary because -z is git's behavior. As long as we already used it and the result can be parsed, then no problem.

@lunny

lunny commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

Everything should have been addressed in #40326

The new test is not necessary because -z is git's behavior. As long as we already used it and the result can be parsed, then no problem.

Thanks! I sent a backport #40362 to v28 and will close this one.

@lunny lunny closed this Nov 13, 2026
@lunny
lunny deleted the fix-affected-files-quoting branch November 13, 2026 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/v28 This PR should be backported to Gitea 28 lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. type/bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants