mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-19 22:33:16 +02:00
Simplify GetCommitMessage
Use git log instead of git rev-list, this way we don't get a line "commit <sha>" at the beginning that we then have to discard again. The test TestGetCommitMsg is becoming a bit pointless now, since it just compares that input and output are identical.
This commit is contained in:
parent
b6a9220343
commit
daf9b8cfa9
@ -137,12 +137,11 @@ func (self *CommitCommands) signoffFlag() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *CommitCommands) GetCommitMessage(commitSha string) (string, error) {
|
func (self *CommitCommands) GetCommitMessage(commitSha string) (string, error) {
|
||||||
cmdArgs := NewGitCmd("rev-list").
|
cmdArgs := NewGitCmd("log").
|
||||||
Arg("--format=%B", "--max-count=1", commitSha).
|
Arg("--format=%B", "--max-count=1", commitSha).
|
||||||
ToArgv()
|
ToArgv()
|
||||||
|
|
||||||
messageWithHeader, err := self.cmd.New(cmdArgs).DontLog().RunWithOutput()
|
message, err := self.cmd.New(cmdArgs).DontLog().RunWithOutput()
|
||||||
message := strings.Join(strings.SplitAfter(messageWithHeader, "\n")[1:], "")
|
|
||||||
return strings.TrimSpace(message), err
|
return strings.TrimSpace(message), err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -260,19 +260,17 @@ func TestGetCommitMsg(t *testing.T) {
|
|||||||
scenarios := []scenario{
|
scenarios := []scenario{
|
||||||
{
|
{
|
||||||
"empty",
|
"empty",
|
||||||
` commit deadbeef`,
|
``,
|
||||||
``,
|
``,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"no line breaks (single line)",
|
"no line breaks (single line)",
|
||||||
`commit deadbeef
|
`use generics to DRY up context code`,
|
||||||
use generics to DRY up context code`,
|
|
||||||
`use generics to DRY up context code`,
|
`use generics to DRY up context code`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"with line breaks",
|
"with line breaks",
|
||||||
`commit deadbeef
|
`Merge pull request #1750 from mark2185/fix-issue-template
|
||||||
Merge pull request #1750 from mark2185/fix-issue-template
|
|
||||||
|
|
||||||
'git-rev parse' should be 'git rev-parse'`,
|
'git-rev parse' should be 'git rev-parse'`,
|
||||||
`Merge pull request #1750 from mark2185/fix-issue-template
|
`Merge pull request #1750 from mark2185/fix-issue-template
|
||||||
@ -285,7 +283,7 @@ Merge pull request #1750 from mark2185/fix-issue-template
|
|||||||
s := s
|
s := s
|
||||||
t.Run(s.testName, func(t *testing.T) {
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
instance := buildCommitCommands(commonDeps{
|
instance := buildCommitCommands(commonDeps{
|
||||||
runner: oscommands.NewFakeRunner(t).ExpectGitArgs([]string{"rev-list", "--format=%B", "--max-count=1", "deadbeef"}, s.input, nil),
|
runner: oscommands.NewFakeRunner(t).ExpectGitArgs([]string{"log", "--format=%B", "--max-count=1", "deadbeef"}, s.input, nil),
|
||||||
})
|
})
|
||||||
|
|
||||||
output, err := instance.GetCommitMessage("deadbeef")
|
output, err := instance.GetCommitMessage("deadbeef")
|
||||||
@ -306,15 +304,14 @@ func TestGetCommitMessageFromHistory(t *testing.T) {
|
|||||||
scenarios := []scenario{
|
scenarios := []scenario{
|
||||||
{
|
{
|
||||||
"Empty message",
|
"Empty message",
|
||||||
oscommands.NewFakeRunner(t).ExpectGitArgs([]string{"log", "-1", "--skip=2", "--pretty=%H"}, "", nil).ExpectGitArgs([]string{"rev-list", "--format=%B", "--max-count=1"}, "", nil),
|
oscommands.NewFakeRunner(t).ExpectGitArgs([]string{"log", "-1", "--skip=2", "--pretty=%H"}, "", nil).ExpectGitArgs([]string{"log", "--format=%B", "--max-count=1"}, "", nil),
|
||||||
func(output string, err error) {
|
func(output string, err error) {
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Default case to retrieve a commit in history",
|
"Default case to retrieve a commit in history",
|
||||||
oscommands.NewFakeRunner(t).ExpectGitArgs([]string{"log", "-1", "--skip=2", "--pretty=%H"}, "sha3 \n", nil).ExpectGitArgs([]string{"rev-list", "--format=%B", "--max-count=1", "sha3"}, `commit sha3
|
oscommands.NewFakeRunner(t).ExpectGitArgs([]string{"log", "-1", "--skip=2", "--pretty=%H"}, "sha3 \n", nil).ExpectGitArgs([]string{"log", "--format=%B", "--max-count=1", "sha3"}, `use generics to DRY up context code`, nil),
|
||||||
use generics to DRY up context code`, nil),
|
|
||||||
func(output string, err error) {
|
func(output string, err error) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "use generics to DRY up context code", output)
|
assert.Equal(t, "use generics to DRY up context code", output)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user