forked from forgejo/forgejo
Support getting changed files when commit ID is EmptySHA
(#26290)
Fixes #26270. Co-Author: @wxiaoguang Thanks @lunny for providing this solution As https://github.com/go-gitea/gitea/issues/26270#issuecomment-1661695151 said, at present we cannot get the names of changed files correctly when the `OldCommitID` is `EmptySHA`. In this PR, the `GetCommitFilesChanged` method is added and will be used to get the changed files by commit ID. References: - https://stackoverflow.com/a/424142 --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
parent
865d2221c0
commit
8a2f019d69
3 changed files with 50 additions and 3 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue