Skip to content

Commit

Permalink
internal/git: take diff stat from merge base
Browse files Browse the repository at this point in the history
The default behavior for `git diff --stat <target>` is to include all
the difference between HEAD and <target> (a diff union), however, we
want only what was changed from <target> to HEAD, regardless how far
<target> already is from HEAD. For this, we need to consider <target> as
our merge base, and for that, we could add `--merge-base` to the
command.

However, the --merge-base option is available only in recent versions of
Git (v2.30+), which are still not installed everywhere, so for that
we're going to use the 'A...B' notation, that for `git diff` means:

    git diff $(git merge-base <taget> HEAD) HEAD

Signed-off-by: Bruno Meneguele <[email protected]>
  • Loading branch information
bmeneg committed Jun 24, 2021
1 parent 0c0280d commit 114b876
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion internal/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func Log(sha1, sha2 string) (string, error) {
return "", errors.Errorf("Can't load git log %s..%s", sha1, sha2)
}

diffCmd := New("diff", "--stat", sha1)
diffCmd := New("diff", "--stat", fmt.Sprintf("%s...", sha1))
diffCmd.Stdout = nil
diffOutput, err := diffCmd.Output()
if err != nil {
Expand Down

0 comments on commit 114b876

Please sign in to comment.