Make GetCommitFileStatus list all files impacted by a merge commit

Enable APIs (such as 'api/v1/repos/{owner}/{repo}/git/commit/{sha1}') to correctly
list all files impacted by a commit (making it mirror GitHub API behaviour).
Previously would only return merge commit files if they where associated
with a conflict resolution.

module/git/commit.go GetCommitFileStatus now use the git log '-m' flag instead of '-c' which does not seem to work
module/git/commit.go parseCommitFileStatus was modified to handle the change in format for merge commits
This commit is contained in:
Laurent Cahour 2022-07-28 10:38:12 +02:00 committed by Thomas Desveaux
parent ee517a6f00
commit 78a823e767

View file

@ -455,17 +455,18 @@ func NewCommitFileStatus() *CommitFileStatus {
func parseCommitFileStatus(fileStatus *CommitFileStatus, stdout io.Reader) {
rd := bufio.NewReader(stdout)
peek, err := rd.Peek(1)
if err != nil {
if err != io.EOF {
log.Error("Unexpected error whilst reading from git log --name-status. Error: %v", err)
}
return
}
if peek[0] == '\n' || peek[0] == '\x00' {
_, _ = rd.Discard(1)
}
for {
// In case of merge commits, Git will add a separator between each
peek, err := rd.Peek(1)
if err != nil {
if err != io.EOF {
log.Error("Unexpected error whilst reading from git log --name-status. Error: %v", err)
}
return
}
if peek[0] == '\n' || peek[0] == '\x00' {
_, _ = rd.Discard(1)
}
modifier, err := rd.ReadSlice('\x00')
if err != nil {
if err != io.EOF {
@ -503,7 +504,7 @@ func GetCommitFileStatus(ctx context.Context, repoPath, commitID string) (*Commi
}()
stderr := new(bytes.Buffer)
args := []string{"log", "--name-status", "-c", "--pretty=format:", "--parents", "--no-renames", "-z", "-1", commitID}
args := []string{"log", "--name-status", "-m", "--pretty=format:", "--parents", "--no-renames", "-z", "-1", commitID}
err := NewCommand(ctx, args...).Run(&RunOpts{
Dir: repoPath,