Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GetAffectedFiles failed when encountering a null old commit #26881

Closed
wants to merge 5 commits into from

Conversation

lng2020
Copy link
Member

@lng2020 lng2020 commented Sep 3, 2023

When using protected/unprotected file patterns, git push --set-upstream xxx xxx will cause an internal server error.
6D9IB}MLNADEJ%QVQD(0V
This bug is because when git push --set-upstream, a null commit is passed to function GetAffectedFiles as oldCommitID, but git diff cannot compare null commits. So when oldCommit is null, we should modify the oldCommitID to empty tree commit("4b825dc642cb6eb9a060e54bf8d69288fbee4904") to use git diff.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Sep 3, 2023
@pull-request-size pull-request-size bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Sep 3, 2023
modules/git/diff.go Outdated Show resolved Hide resolved
lng2020 and others added 3 commits September 3, 2023 15:04
Co-authored-by: CaiCandong <50507092+CaiCandong@users.noreply.github.com>
…etAffectedFiles

# Conflicts:
#	modules/git/diff.go
@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 Sep 3, 2023
@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 Sep 3, 2023
@wxiaoguang
Copy link
Contributor

Wait, is it right to get all changed file between current commit and the empty tree commit?

@KN4CK3R
Copy link
Member

KN4CK3R commented Sep 3, 2023

I think the solution is ok but maybe the check should not be in that method but some frames up the callstack.

Edit: The solution could be a problem because this will now scan the whole repo for (dis)allowed files and that may conflict with already existing files which are not modified in the new branch. So it may be better to use the diverging commit id with the default branch and only fallback to the empty tree commit if there is none.

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Sep 3, 2023

The solution could be a problem because this will now scan the whole repo for (dis)allowed files and that may conflict with already existing files which are not modified in the new branch.

Yup, I think so too.

And I recalled this PR (not fully related but the "empty sha" behavior should be explicitly clarified)

@wxiaoguang wxiaoguang added the status/blocked This PR cannot be merged yet, i.e. because it depends on another unmerged PR label Sep 3, 2023
@lunny
Copy link
Member

lunny commented Sep 3, 2023

The solution could be a problem because this will now scan the whole repo for (dis)allowed files and that may conflict with already existing files which are not modified in the new branch.

Yup, I think so too.

And I recalled this PR (not fully related but the "empty sha" behavior should be explicitly clarified)

* [Support getting changed files when commit ID is `EmptySHA` #26290](https://github.com/go-gitea/gitea/pull/26290)

Maybe we need to check all possbile places which contains oldcommit and newcommit and handle them like #26290 did.

@silverwind
Copy link
Member

silverwind commented Sep 8, 2023

Merge this? Edit: Nevermind, i see the blocked.

@lunny
Copy link
Member

lunny commented Apr 30, 2024

This should have been replaced by #26290 . @Zettat123 @lng2020

@lunny
Copy link
Member

lunny commented May 27, 2024

Close as outdated.

@lunny lunny closed this May 27, 2024
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Aug 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. status/blocked This PR cannot be merged yet, i.e. because it depends on another unmerged PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants