mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-10 07:36:27 -04:00
Fix copying a file's absolute path when running in a linked worktree (#5523)
When copying a file's absolute path in a worktree, the result would be relative to the main repo rather than the worktree you're in. Fixes #5522.
This commit is contained in:
commit
ce7f8a829d
|
|
@ -248,7 +248,11 @@ func (self *CommitFilesController) openCopyMenu() error {
|
|||
copyAbsolutePathItem := &types.MenuItem{
|
||||
Label: self.c.Tr.CopyAbsoluteFilePath,
|
||||
OnPress: func() error {
|
||||
if err := self.c.OS().CopyToClipboard(filepath.Join(self.c.Git().RepoPaths.RepoPath(), node.GetPath())); err != nil {
|
||||
absPath, err := filepath.Abs(node.GetPath())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := self.c.OS().CopyToClipboard(absPath); err != nil {
|
||||
return err
|
||||
}
|
||||
self.c.Toast(self.c.Tr.FilePathCopiedToast)
|
||||
|
|
|
|||
|
|
@ -1199,7 +1199,11 @@ func (self *FilesController) openCopyMenu() error {
|
|||
copyAbsolutePathItem := &types.MenuItem{
|
||||
Label: self.c.Tr.CopyAbsoluteFilePath,
|
||||
OnPress: func() error {
|
||||
if err := self.c.OS().CopyToClipboard(filepath.Join(self.c.Git().RepoPaths.RepoPath(), node.GetPath())); err != nil {
|
||||
absPath, err := filepath.Abs(node.GetPath())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := self.c.OS().CopyToClipboard(absPath); err != nil {
|
||||
return err
|
||||
}
|
||||
self.c.Toast(self.c.Tr.FilePathCopiedToast)
|
||||
|
|
|
|||
|
|
@ -22,6 +22,12 @@ var CopyToClipboard = NewIntegrationTest(NewIntegrationTestArgs{
|
|||
config.GetUserConfig().OS.CopyToClipboardCmd = "printf '%s' {{text}} > clipboard"
|
||||
},
|
||||
SetupRepo: func(shell *Shell) {
|
||||
// Run the test in a linked worktree so that we catch bugs where we
|
||||
// use the main repo's path instead of the current worktree's path.
|
||||
shell.EmptyCommit("initial commit")
|
||||
shell.AddWorktree("HEAD", "../linked-worktree", "mybranch")
|
||||
shell.Chdir("../linked-worktree")
|
||||
|
||||
shell.CreateDir("dir")
|
||||
shell.CreateFileAndAdd("dir/file1", "1st line\n")
|
||||
shell.Commit("1")
|
||||
|
|
@ -38,6 +44,7 @@ var CopyToClipboard = NewIntegrationTest(NewIntegrationTestArgs{
|
|||
Contains("3").IsSelected(),
|
||||
Contains("2"),
|
||||
Contains("1"),
|
||||
Contains("initial commit"),
|
||||
).
|
||||
SelectNextItem().
|
||||
PressEnter()
|
||||
|
|
@ -80,9 +87,9 @@ var CopyToClipboard = NewIntegrationTest(NewIntegrationTestArgs{
|
|||
Confirm().
|
||||
Tap(func() {
|
||||
t.ExpectToast(Equals("File path copied to clipboard"))
|
||||
repoDir, _ := os.Getwd()
|
||||
worktreeDir, _ := os.Getwd()
|
||||
// On windows the following path would have backslashes, but we don't run integration tests on windows yet.
|
||||
expectClipboard(t, Equals(repoDir+"/dir/file1"))
|
||||
expectClipboard(t, Equals(worktreeDir+"/dir/file1"))
|
||||
})
|
||||
}).
|
||||
Press(keys.Files.CopyFileInfoToClipboard).
|
||||
|
|
|
|||
|
|
@ -21,7 +21,13 @@ var CopyMenu = NewIntegrationTest(NewIntegrationTestArgs{
|
|||
SetupConfig: func(config *config.AppConfig) {
|
||||
config.GetUserConfig().OS.CopyToClipboardCmd = "printf '%s' {{text}} > clipboard"
|
||||
},
|
||||
SetupRepo: func(shell *Shell) {},
|
||||
SetupRepo: func(shell *Shell) {
|
||||
// Run the test in a linked worktree so that we catch bugs where we
|
||||
// use the main repo's path instead of the current worktree's path.
|
||||
shell.EmptyCommit("initial commit")
|
||||
shell.AddWorktree("HEAD", "../linked-worktree", "mybranch")
|
||||
shell.Chdir("../linked-worktree")
|
||||
},
|
||||
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||
// Disabled item
|
||||
t.Views().Files().
|
||||
|
|
@ -130,9 +136,9 @@ var CopyMenu = NewIntegrationTest(NewIntegrationTestArgs{
|
|||
|
||||
t.ExpectToast(Equals("File path copied to clipboard"))
|
||||
|
||||
repoDir, _ := os.Getwd()
|
||||
worktreeDir, _ := os.Getwd()
|
||||
// On windows the following path would have backslashes, but we don't run integration tests on windows yet.
|
||||
expectClipboard(t, Equals(repoDir+"/dir/1-unstaged_file"))
|
||||
expectClipboard(t, Equals(worktreeDir+"/dir/1-unstaged_file"))
|
||||
})
|
||||
|
||||
// Selected path diff on a single (unstaged) file
|
||||
|
|
|
|||
Loading…
Reference in a new issue