mirror of
https://codeberg.org/davrot/forgejo.git
synced 2025-05-18 17:00:02 +02:00
fix: make branch protection work for new branches
- If `GetAffectedFiles` is called for a push with an empty oldCommitID,
then set the oldCommitID to the empty tree. This will effictively diff
all the changes included in the push, which is the expected behavior for
branches.
- Integration test added.
- Resolves #5683
- Port of gitea#31778 but implemented differently.
(cherry picked from commit f5e025917f
)
This commit is contained in:
parent
96f0c76648
commit
1f62fe8ae0
3 changed files with 35 additions and 0 deletions
|
@ -272,6 +272,17 @@ func CutDiffAroundLine(originalDiff io.Reader, line int64, old bool, numbersOfLi
|
|||
|
||||
// GetAffectedFiles returns the affected files between two commits
|
||||
func GetAffectedFiles(repo *Repository, oldCommitID, newCommitID string, env []string) ([]string, error) {
|
||||
objectFormat, err := repo.GetObjectFormat()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// If the oldCommitID is empty, then we must assume its a new branch, so diff
|
||||
// against the empty tree. So all changes of this new branch are included.
|
||||
if oldCommitID == objectFormat.EmptyObjectID().String() {
|
||||
oldCommitID = objectFormat.EmptyTree().String()
|
||||
}
|
||||
|
||||
stdoutReader, stdoutWriter, err := os.Pipe()
|
||||
if err != nil {
|
||||
log.Error("Unable to create os.Pipe for %s", repo.Path)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue