Skip to content

Commit

Permalink
use 'diff-tree' instead of 'diff'
Browse files Browse the repository at this point in the history
  • Loading branch information
Zettat123 committed Aug 3, 2023
1 parent 2e9656b commit 17afa99
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 5 additions & 4 deletions modules/git/repo_compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,15 @@ func (repo *Repository) GetPatch(base, head string, w io.Writer) error {

// GetFilesChangedBetween returns a list of all files that have been changed between the given commits
// If base is undefined empty SHA (zeros), it only returns the files changed in the head commit
// If base is the SHA of an empty tree (EmptyTreeSHA), it returns the files changes from the initial commit to the head commit
func (repo *Repository) GetFilesChangedBetween(base, head string) ([]string, error) {
var stdout string
var err error
cmd := NewCommand(repo.Ctx, "diff-tree", "--name-only", "--root", "--no-commit-id", "-r", "-z")
if base == EmptySHA {
stdout, _, err = NewCommand(repo.Ctx, "diff-tree", "--name-only", "--root", "--no-commit-id", "-r", "-z").AddDynamicArguments(head).RunStdString(&RunOpts{Dir: repo.Path})
cmd.AddDynamicArguments(head)
} else {
stdout, _, err = NewCommand(repo.Ctx, "diff", "--name-only", "-z").AddDynamicArguments(base + ".." + head).RunStdString(&RunOpts{Dir: repo.Path})
cmd.AddDynamicArguments(base + ".." + head)
}
stdout, _, err := cmd.RunStdString(&RunOpts{Dir: repo.Path})
if err != nil {
return nil, err
}
Expand Down
5 changes: 5 additions & 0 deletions modules/git/repo_compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ func TestGetCommitFilesChanged(t *testing.T) {
"8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2",
[]string{"file2.txt"},
},
{
"95bb4d39648ee7e325106df01a621c530863a653",
"8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2",
[]string{"file2.txt"},
},
{
EmptyTreeSHA,
"8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2",
Expand Down

0 comments on commit 17afa99

Please sign in to comment.