diff options
Diffstat (limited to 'modules/git/repo_compare.go')
-rw-r--r-- | modules/git/repo_compare.go | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/modules/git/repo_compare.go b/modules/git/repo_compare.go index e706275856..aad725fa9d 100644 --- a/modules/git/repo_compare.go +++ b/modules/git/repo_compare.go @@ -280,8 +280,16 @@ 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) { - stdout, _, err := NewCommand(repo.Ctx, "diff", "--name-only", "-z").AddDynamicArguments(base + ".." + head).RunStdString(&RunOpts{Dir: repo.Path}) + cmd := NewCommand(repo.Ctx, "diff-tree", "--name-only", "--root", "--no-commit-id", "-r", "-z") + if base == EmptySHA { + cmd.AddDynamicArguments(head) + } else { + cmd.AddDynamicArguments(base, head) + } + stdout, _, err := cmd.RunStdString(&RunOpts{Dir: repo.Path}) if err != nil { return nil, err } |