diff --git a/pkg/gui/controllers/commits_files_controller.go b/pkg/gui/controllers/commits_files_controller.go index b8995e7bd..e945ef8ca 100644 --- a/pkg/gui/controllers/commits_files_controller.go +++ b/pkg/gui/controllers/commits_files_controller.go @@ -3,7 +3,6 @@ package controllers import ( "errors" "fmt" - "path/filepath" "strings" "github.com/jesseduffield/lazygit/pkg/commands/git_commands" @@ -267,7 +266,7 @@ func (self *CommitFilesController) openCopyMenu() error { copyAbsolutePathItem := &types.MenuItem{ Label: self.c.Tr.CopyAbsoluteFilePath, OnPress: func() error { - absPath, err := filepath.Abs(node.GetPath()) + absPath, err := self.c.Helpers().Diff.AbsolutePathOfFileOfDiff(node.GetPath()) if err != nil { return err } diff --git a/pkg/gui/controllers/helpers/diff_helper.go b/pkg/gui/controllers/helpers/diff_helper.go index f620aed66..1e94c9ac7 100644 --- a/pkg/gui/controllers/helpers/diff_helper.go +++ b/pkg/gui/controllers/helpers/diff_helper.go @@ -252,6 +252,12 @@ func (self *DiffHelper) OpenFileOfDiff(path string) error { return self.filesHelper.OpenFile(self.pathInWorktreeOfDiff(path)) } +// AbsolutePathOfFileOfDiff returns the absolute path of a file of the diff that the +// current side panel shows, in the worktree that EditFilesOfDiff opens it from. +func (self *DiffHelper) AbsolutePathOfFileOfDiff(path string) (string, error) { + return filepath.Abs(self.pathInWorktreeOfDiff(path)) +} + // otherWorktreeOfDiff returns the path of the worktree to open files of the diff in // the current side panel from, if that isn't the current worktree. If the diff is of a // commit of a branch, and another worktree has that branch checked out, that is the diff --git a/pkg/integration/tests/worktree/open_file_of_branch_in_other_worktree.go b/pkg/integration/tests/worktree/open_file_of_branch_in_other_worktree.go index 78229d6e4..e0bf265a2 100644 --- a/pkg/integration/tests/worktree/open_file_of_branch_in_other_worktree.go +++ b/pkg/integration/tests/worktree/open_file_of_branch_in_other_worktree.go @@ -58,10 +58,7 @@ var OpenFileOfBranchInOtherWorktree = NewIntegrationTest(NewIntegrationTestArgs{ t.ExpectToast(Equals("File path copied to clipboard")) - /* EXPECTED: t.FileSystem().FileContent("clipboard", Contains("/linked-worktree/file.txt")) - ACTUAL: */ - t.FileSystem().FileContent("clipboard", Contains("/repo/file.txt")) }) }, })