Skip to content

Commit

Permalink
internal/git: allow specific ref to be used in LastCommitMessage()
Browse files Browse the repository at this point in the history
LastCommitMessage was querying for the last commit message from HEAD
only, hard-coded. So if the user uses --source option for creating an MR
that doesn't match with the branch he's checked-out the commit log
prompted will be from HEAD instead of what's present in the requested
source remote:branch through --source option.

Signed-off-by: Bruno Meneguele <[email protected]>
  • Loading branch information
bmeneg committed Jun 24, 2021
1 parent e371958 commit fb66a37
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/mr_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func mrText(sourceRemote, sourceBranch, targetRemote, targetBranch string, cover
numCommits := git.NumberCommits(target, source)
if numCommits == 1 {
var err error
commitMsg, err = git.LastCommitMessage()
commitMsg, err = git.LastCommitMessage(source)
if err != nil {
return "", err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ func PagerCommand() (string, []string) {
}

// LastCommitMessage returns the last commits message as one line
func LastCommitMessage() (string, error) {
cmd := New("show", "-s", "--format=%s%n%+b", "HEAD")
func LastCommitMessage(sha string) (string, error) {
cmd := New("show", "-s", "--format=%s%n%+b", sha)
cmd.Stdout = nil
msg, err := cmd.Output()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/git/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestCommentChar(t *testing.T) {
}

func TestLastCommitMessage(t *testing.T) {
lcm, err := LastCommitMessage()
lcm, err := LastCommitMessage("HEAD")
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit fb66a37

Please sign in to comment.