Skip to content

Commit 8a328a5

Browse files
authored
Fix copying commit author to clipboard (jesseduffield#3936)
- **PR Description** This included single quotes in strange places in the copied text. Fixes jesseduffield#3933. - **Please check if the PR fulfills these requirements** * [x] Cheatsheets are up-to-date (run `go generate ./...`) * [x] Code has been formatted (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#code-formatting)) * [x] Tests have been added/updated (see [here](https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md) for the integration test guide) * [ ] Text is internationalised (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#internationalisation)) * [ ] If a new UserConfig entry was added, make sure it can be hot-reloaded (see [here](https://github.com/jesseduffield/lazygit/blob/master/docs/dev/Codebase_Guide.md#using-userconfig)) * [ ] Docs have been updated if necessary * [x] You've read through your own file changes for silly mistakes etc
2 parents a04ad24 + 3d56357 commit 8a328a5

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

pkg/commands/git_commands/commit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ type Author struct {
189189

190190
func (self *CommitCommands) GetCommitAuthor(commitHash string) (Author, error) {
191191
cmdArgs := NewGitCmd("show").
192-
Arg("--no-patch", "--pretty=format:'%an%x00%ae'", commitHash).
192+
Arg("--no-patch", "--pretty=format:%an%x00%ae", commitHash).
193193
ToArgv()
194194

195195
output, err := self.cmd.New(cmdArgs).DontLog().RunWithOutput()
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package commit
2+
3+
import (
4+
"github.com/jesseduffield/lazygit/pkg/config"
5+
. "github.com/jesseduffield/lazygit/pkg/integration/components"
6+
)
7+
8+
// We're emulating the clipboard by writing to a file called clipboard
9+
10+
var CopyAuthorToClipboard = NewIntegrationTest(NewIntegrationTestArgs{
11+
Description: "Copy a commit author name to the clipboard",
12+
ExtraCmdArgs: []string{},
13+
Skip: false,
14+
SetupConfig: func(config *config.AppConfig) {
15+
// Include delimiters around the text so that we can assert on the entire content
16+
config.GetUserConfig().OS.CopyToClipboardCmd = "echo /{{text}}/ > clipboard"
17+
},
18+
19+
SetupRepo: func(shell *Shell) {
20+
shell.SetAuthor("John Doe", "[email protected]")
21+
shell.EmptyCommit("commit")
22+
},
23+
24+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
25+
t.Views().Commits().
26+
Focus().
27+
Lines(
28+
Contains("commit").IsSelected(),
29+
).
30+
Press(keys.Commits.CopyCommitAttributeToClipboard)
31+
32+
t.ExpectPopup().Menu().
33+
Title(Equals("Copy to clipboard")).
34+
Select(Contains("Commit author")).
35+
Confirm()
36+
37+
t.ExpectToast(Equals("Commit author copied to clipboard"))
38+
39+
t.Views().Files().
40+
Focus().
41+
Press(keys.Files.RefreshFiles).
42+
Lines(
43+
Contains("clipboard").IsSelected(),
44+
)
45+
46+
t.Views().Main().Content(Contains("/John Doe <[email protected]>/"))
47+
},
48+
})

pkg/integration/tests/test_list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ var tests = []*components.IntegrationTest{
8787
commit.CommitWithGlobalPrefix,
8888
commit.CommitWithNonMatchingBranchName,
8989
commit.CommitWithPrefix,
90+
commit.CopyAuthorToClipboard,
9091
commit.CreateAmendCommit,
9192
commit.CreateFixupCommitInBranchStack,
9293
commit.CreateTag,

0 commit comments

Comments
 (0)