-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a "Copy to clipboard" menu to the Commit Files panel #4271
Merged
stefanhaller
merged 2 commits into
master
from
add-clipboard-menu-to-commit-files-panel
Feb 19, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package diff | ||
|
||
import ( | ||
"github.com/jesseduffield/lazygit/pkg/config" | ||
. "github.com/jesseduffield/lazygit/pkg/integration/components" | ||
) | ||
|
||
// note: this is required to simulate the clipboard during CI | ||
func expectClipboard(t *TestDriver, matcher *TextMatcher) { | ||
defer t.Shell().DeleteFile("clipboard") | ||
|
||
t.FileSystem().FileContent("clipboard", matcher) | ||
} | ||
|
||
var CopyToClipboard = NewIntegrationTest(NewIntegrationTestArgs{ | ||
Description: "The copy menu allows to copy name and diff of selected/all files", | ||
ExtraCmdArgs: []string{}, | ||
Skip: false, | ||
SetupConfig: func(config *config.AppConfig) { | ||
config.GetUserConfig().OS.CopyToClipboardCmd = "printf '%s' {{text}} > clipboard" | ||
}, | ||
SetupRepo: func(shell *Shell) { | ||
shell.CreateDir("dir") | ||
shell.CreateFileAndAdd("dir/file1", "1st line\n") | ||
shell.Commit("1") | ||
shell.CreateFileAndAdd("dir/file1", "1st line\n2nd line\n") | ||
shell.CreateFileAndAdd("dir/file2", "file2\n") | ||
shell.Commit("2") | ||
}, | ||
Run: func(t *TestDriver, keys config.KeybindingConfig) { | ||
t.Views().Commits(). | ||
Focus(). | ||
Lines( | ||
Contains("2").IsSelected(), | ||
Contains("1"), | ||
). | ||
PressEnter() | ||
|
||
t.Views().CommitFiles(). | ||
IsFocused(). | ||
Lines( | ||
Contains("dir").IsSelected(), | ||
Contains("file1"), | ||
Contains("file2"), | ||
). | ||
NavigateToLine(Contains("file1")). | ||
Press(keys.Files.CopyFileInfoToClipboard). | ||
Tap(func() { | ||
t.ExpectPopup().Menu(). | ||
Title(Equals("Copy to clipboard")). | ||
Select(Contains("File name")). | ||
Confirm(). | ||
Tap(func() { | ||
t.ExpectToast(Equals("File name copied to clipboard")) | ||
expectClipboard(t, Equals("file1")) | ||
}) | ||
}). | ||
Press(keys.Files.CopyFileInfoToClipboard). | ||
Tap(func() { | ||
t.ExpectPopup().Menu(). | ||
Title(Equals("Copy to clipboard")). | ||
Select(Contains("Path")). | ||
Confirm(). | ||
Tap(func() { | ||
t.ExpectToast(Equals("File path copied to clipboard")) | ||
expectClipboard(t, Equals("dir/file1")) | ||
}) | ||
}). | ||
Press(keys.Files.CopyFileInfoToClipboard). | ||
Tap(func() { | ||
t.ExpectPopup().Menu(). | ||
Title(Equals("Copy to clipboard")). | ||
Select(Contains("Diff of selected file")). | ||
Confirm(). | ||
Tap(func() { | ||
t.ExpectToast(Equals("File diff copied to clipboard")) | ||
expectClipboard(t, | ||
Contains("diff --git a/dir/file1 b/dir/file1").Contains("+2nd line").DoesNotContain("+1st line"). | ||
DoesNotContain("diff --git a/dir/file2 b/dir/file2").DoesNotContain("+file2")) | ||
}) | ||
}). | ||
Press(keys.Files.CopyFileInfoToClipboard). | ||
Tap(func() { | ||
t.ExpectPopup().Menu(). | ||
Title(Equals("Copy to clipboard")). | ||
Select(Contains("Diff of all files")). | ||
Confirm(). | ||
Tap(func() { | ||
t.ExpectToast(Equals("All files diff copied to clipboard")) | ||
expectClipboard(t, | ||
Contains("diff --git a/dir/file1 b/dir/file1").Contains("+2nd line").DoesNotContain("+1st line"). | ||
Contains("diff --git a/dir/file2 b/dir/file2").Contains("+file2")) | ||
}) | ||
}) | ||
|
||
t.Views().Commits(). | ||
Focus(). | ||
// Select both commits | ||
Press(keys.Universal.RangeSelectDown). | ||
PressEnter() | ||
|
||
t.Views().CommitFiles(). | ||
IsFocused(). | ||
Lines( | ||
Contains("dir").IsSelected(), | ||
Contains("file1"), | ||
Contains("file2"), | ||
). | ||
NavigateToLine(Contains("file1")). | ||
Press(keys.Files.CopyFileInfoToClipboard). | ||
Tap(func() { | ||
t.ExpectPopup().Menu(). | ||
Title(Equals("Copy to clipboard")). | ||
Select(Contains("Diff of selected file")). | ||
Confirm(). | ||
Tap(func() { | ||
t.ExpectToast(Equals("File diff copied to clipboard")) | ||
expectClipboard(t, | ||
Contains("diff --git a/dir/file1 b/dir/file1").Contains("+1st line").Contains("+2nd line")) | ||
}) | ||
}) | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm using a key from the Files section here, which could be considered wrong. Actually I think it's ok though, I prefer this both to adding a new one to the CommitFiles section, and to moving it into Universal. It's also not the first time we do this, we are already using a few others from the Files section here.