Skip to content

Commit 17afa99

Browse files
committed
use 'diff-tree' instead of 'diff'
1 parent 2e9656b commit 17afa99

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

modules/git/repo_compare.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,15 @@ func (repo *Repository) GetPatch(base, head string, w io.Writer) error {
281281

282282
// GetFilesChangedBetween returns a list of all files that have been changed between the given commits
283283
// If base is undefined empty SHA (zeros), it only returns the files changed in the head commit
284+
// If base is the SHA of an empty tree (EmptyTreeSHA), it returns the files changes from the initial commit to the head commit
284285
func (repo *Repository) GetFilesChangedBetween(base, head string) ([]string, error) {
285-
var stdout string
286-
var err error
286+
cmd := NewCommand(repo.Ctx, "diff-tree", "--name-only", "--root", "--no-commit-id", "-r", "-z")
287287
if base == EmptySHA {
288-
stdout, _, err = NewCommand(repo.Ctx, "diff-tree", "--name-only", "--root", "--no-commit-id", "-r", "-z").AddDynamicArguments(head).RunStdString(&RunOpts{Dir: repo.Path})
288+
cmd.AddDynamicArguments(head)
289289
} else {
290-
stdout, _, err = NewCommand(repo.Ctx, "diff", "--name-only", "-z").AddDynamicArguments(base + ".." + head).RunStdString(&RunOpts{Dir: repo.Path})
290+
cmd.AddDynamicArguments(base + ".." + head)
291291
}
292+
stdout, _, err := cmd.RunStdString(&RunOpts{Dir: repo.Path})
292293
if err != nil {
293294
return nil, err
294295
}

modules/git/repo_compare_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ func TestGetCommitFilesChanged(t *testing.T) {
140140
"8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2",
141141
[]string{"file2.txt"},
142142
},
143+
{
144+
"95bb4d39648ee7e325106df01a621c530863a653",
145+
"8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2",
146+
[]string{"file2.txt"},
147+
},
143148
{
144149
EmptyTreeSHA,
145150
"8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2",

0 commit comments

Comments
 (0)