Repository: jesseduffield/lazygit (language: go)

Issue:
Duplicate line breaks when copying commit message to clipboard / Rewording commit
**Describe the bug**

When using the "copy commit message to clipboard" action, the message will end up in the clipboard with duplicate line breaks. The same issue also seems to affect the "Reword Commit" command.

I tried to dig around in the code a bit and I think this might be caused by `GetCommitMessage()` in [pkg/commands/git_commands/commit.go](https://github.com/jesseduffield/lazygit/blob/f4011643dda14c6da522dcd172b66b2d2cadb02b/pkg/commands/git_commands/commit.go#L73).

```
	[...]
	message := strings.Join(strings.SplitAfter(messageWithHeader, "\n")[1:], "\n")
```

The `SplitAfter` will not remove the line breaks, and the `Join` will add new ones, causing the duplicates.

I'd be happy to file a PR for this - if somebody with more knowledge of the code base can confirm that this actually looks like / is the root cause (and whether tests can be added for it).

**To Reproduce**
Steps to reproduce the behavior:
1. Select a commit in 'Commits' view (e.g. c7c4a375a98130e746af021fd706e354cf989d1f)
2. Invoke 'copy commit message to clipboard' (CTRL+y)
3. Paste message into an editor

**Expected behavior**

```
Merge pull request #1750 from mark2185/fix-issue-template

'git-rev parse' should be 'git rev-parse'
```

**Actual behavior**

```
Merge pull request #1750 from mark2185/fix-issue-template



'git-rev parse' should be 'git rev-parse'
```

**Screenshots**
n/a

**Desktop (please complete the following information):**
 - OS: Linux
 - Lazygit Version: v0.33

**Additional context**
n/a



Discussion / hints:
@moha-gh Nice, this indeed looks like the cause of the error. 

I've drafted a unit test that you can start off with that is currently broken due to the bug: 
```go
func TestGetCommitMsg(t *testing.T) {
	type scenario struct {
		testName       string
		input          string
		expectedOutput string
	}
	scenarios := []scenario{
		{
			"with line breaks", ` commit deadbeef
Merge pull request #1750 from mark2185/fix-issue-template

'git-rev parse' should be 'git rev-parse'`, `Merge pull request #1750 from mark2185/fix-issue-template

'git-rev parse' should be 'git rev-parse'`,
		},
	}

	for _, s := range scenarios {
		s := s
		t.Run(s.testName, func(t *testing.T) {
			instance := buildCommitCommands(commonDeps{
				runner: oscommands.NewFakeRunner(t).Expect("git rev-list --format=%B --max-count=1 deadbeef", s.input, nil),
			})

			output, err := instance.GetCommitMessage("deadbeef")

			assert.NoError(t, err)

			assert.Equal(t, s.expectedOutput, output)

		})
	}
```

 Running this test gives:
```
|| === RUN   TestGetCommitMsg/with_line_breaks
||     commit_test.go:152: 
||         	Error Trace:	commit_test.go:152
||         	Error:      	Not equal: 
||         	            	expected: "Merge pull request #1750 from mark2185/fix-issue-template\n\n'git-rev parse' should be 'git rev-parse'\n"
||         	            	actual  : "Merge pull request #1750 from mark2185/fix-issue-template\n\n\n\n'git-rev parse' should be 'git rev-parse'"
```
Nice catch @moha-gh , looks to be the cause of the problem

Fix patch:
diff --git a/pkg/commands/git_commands/commit.go b/pkg/commands/git_commands/commit.go
index 38f50bdda5c..75256878f84 100644
--- a/pkg/commands/git_commands/commit.go
+++ b/pkg/commands/git_commands/commit.go
@@ -70,7 +70,7 @@ func (self *CommitCommands) GetHeadCommitMessage() (string, error) {
 func (self *CommitCommands) GetCommitMessage(commitSha string) (string, error) {
 	cmdStr := "git rev-list --format=%B --max-count=1 " + commitSha
 	messageWithHeader, err := self.cmd.New(cmdStr).DontLog().RunWithOutput()
-	message := strings.Join(strings.SplitAfter(messageWithHeader, "\n")[1:], "\n")
+	message := strings.Join(strings.SplitAfter(messageWithHeader, "\n")[1:], "")
 	return strings.TrimSpace(message), err
 }
 


Test patch:
diff --git a/pkg/commands/git_commands/commit_test.go b/pkg/commands/git_commands/commit_test.go
index 08ee7e5cc01..96a46ecf40c 100644
--- a/pkg/commands/git_commands/commit_test.go
+++ b/pkg/commands/git_commands/commit_test.go
@@ -161,3 +161,49 @@ func TestCommitShowCmdObj(t *testing.T) {
 		})
 	}
 }
+
+func TestGetCommitMsg(t *testing.T) {
+	type scenario struct {
+		testName       string
+		input          string
+		expectedOutput string
+	}
+	scenarios := []scenario{
+		{
+			"empty",
+			` commit deadbeef`,
+			``,
+		},
+		{
+			"no line breaks (single line)",
+			`commit deadbeef
+use generics to DRY up context code`,
+			`use generics to DRY up context code`,
+		},
+		{
+			"with line breaks",
+			`commit deadbeef
+Merge pull request #1750 from mark2185/fix-issue-template
+
+'git-rev parse' should be 'git rev-parse'`,
+			`Merge pull request #1750 from mark2185/fix-issue-template
+
+'git-rev parse' should be 'git rev-parse'`,
+		},
+	}
+
+	for _, s := range scenarios {
+		s := s
+		t.Run(s.testName, func(t *testing.T) {
+			instance := buildCommitCommands(commonDeps{
+				runner: oscommands.NewFakeRunner(t).Expect("git rev-list --format=%B --max-count=1 deadbeef", s.input, nil),
+			})
+
+			output, err := instance.GetCommitMessage("deadbeef")
+
+			assert.NoError(t, err)
+
+			assert.Equal(t, s.expectedOutput, output)
+		})
+	}
+}