From 8ba00a86f29ded4c4e06cf7d1ad4e6ce5e677726 Mon Sep 17 00:00:00 2001 From: lng2020 Date: Sun, 3 Sep 2023 12:45:43 +0800 Subject: [PATCH 1/3] fix GetAffectedFiles failed when encountering null old commit --- modules/git/diff.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/git/diff.go b/modules/git/diff.go index 10ef3d83fb..0699b179fa 100644 --- a/modules/git/diff.go +++ b/modules/git/diff.go @@ -272,6 +272,10 @@ 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) { + // If the old commit is the null commit, then we need to use the empty tree + if oldCommitID == "0000000000000000000000000000000000000000" { + oldCommitID = "4b825dc642cb6eb9a060e54bf8d69288fbee4904" + } stdoutReader, stdoutWriter, err := os.Pipe() if err != nil { log.Error("Unable to create os.Pipe for %s", repo.Path) From 72e7cc2b7b5b49fcf1840b239f78bac3e097fb7a Mon Sep 17 00:00:00 2001 From: Nanguan Lin <70063547+lng2020@users.noreply.github.com> Date: Sun, 3 Sep 2023 15:04:38 +0800 Subject: [PATCH 2/3] Update modules/git/diff.go Co-authored-by: CaiCandong <50507092+CaiCandong@users.noreply.github.com> --- modules/git/diff.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/git/diff.go b/modules/git/diff.go index 0699b179fa..ba806f6dc0 100644 --- a/modules/git/diff.go +++ b/modules/git/diff.go @@ -273,8 +273,9 @@ 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) { // If the old commit is the null commit, then we need to use the empty tree - if oldCommitID == "0000000000000000000000000000000000000000" { - oldCommitID = "4b825dc642cb6eb9a060e54bf8d69288fbee4904" + if oldCommitID == EmptySHA { + oldCommitID = EmptyTreeSHA + } } stdoutReader, stdoutWriter, err := os.Pipe() if err != nil { From d95302c5d539e73e18c12fc4713433cb0190dbf2 Mon Sep 17 00:00:00 2001 From: lng2020 Date: Sun, 3 Sep 2023 15:06:45 +0800 Subject: [PATCH 3/3] fix --- modules/git/diff.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/git/diff.go b/modules/git/diff.go index 0699b179fa..946cd248ff 100644 --- a/modules/git/diff.go +++ b/modules/git/diff.go @@ -273,8 +273,8 @@ 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) { // If the old commit is the null commit, then we need to use the empty tree - if oldCommitID == "0000000000000000000000000000000000000000" { - oldCommitID = "4b825dc642cb6eb9a060e54bf8d69288fbee4904" + if oldCommitID == EmptySHA { + oldCommitID = EmptyTreeSHA } stdoutReader, stdoutWriter, err := os.Pipe() if err != nil {