From f343c8fd502d2b26eee161d0b493502ed242f888 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Fri, 9 Oct 2026 19:19:48 +0200 Subject: [PATCH] Add a way to run GetDiff in another worktree The next commit carries a line of a diff forward to the file as another worktree has it, and needs to diff against that worktree's working copy for this. Co-Authored-By: Claude Opus 5.5 (1M context) --- pkg/commands/git_commands/diff.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pkg/commands/git_commands/diff.go b/pkg/commands/git_commands/diff.go index ef70d0422..910db7600 100644 --- a/pkg/commands/git_commands/diff.go +++ b/pkg/commands/git_commands/diff.go @@ -186,15 +186,26 @@ func (self *DiffCommands) CustomPatchDiffCmdObj(dir string, mode DiffMode) *osco // want to restrict the diff to specific paths, pass them in additionalArgs // after the `--`. func (self *DiffCommands) GetDiff(staged bool, additionalArgs ...string) (string, error) { + return self.getDiffCmdObj(self.repoPaths.worktreePath, staged, additionalArgs).RunWithOutput() +} + +// GetDiffInOtherWorktree is GetDiff without --staged, run in the worktree at +// worktreePath. That has to be a worktree of our repo other than the current one. A +// diff against the working copy is then a diff against that worktree's files. +func (self *DiffCommands) GetDiffInOtherWorktree(worktreePath string, additionalArgs ...string) (string, error) { + return ForOtherRepo(self.getDiffCmdObj(worktreePath, false, additionalArgs)).RunWithOutput() +} + +func (self *DiffCommands) getDiffCmdObj(worktreePath string, staged bool, additionalArgs []string) *oscommands.CmdObj { return self.cmd.New( NewGitCmd("diff"). ParseableDiffPrefixes(). Arg("--no-ext-diff", "--no-color"). ArgIf(staged, "--staged"). - Dir(self.repoPaths.worktreePath). + Dir(worktreePath). Arg(additionalArgs...). ToArgv(), - ).DontLog().RunWithOutput() + ).DontLog() } type DiffToolCmdOptions struct {