From 339b4c45554a496528c492efb92267fddbecabb6 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Mon, 14 Sep 2026 10:31:20 +0200 Subject: [PATCH] Export ForOtherRepo The recent repos helper is about to run a git command against each repo in the menu, and it needs the same treatment of GIT_DIR and GIT_WORK_TREE that everything else pointed at another repo gets. Co-Authored-By: Claude Opus 5 (1M context) --- pkg/commands/git_commands/git_command_builder.go | 4 ++-- pkg/commands/git_commands/repo_paths.go | 4 ++-- pkg/commands/git_commands/submodule.go | 10 +++++----- pkg/commands/git_commands/worktree.go | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pkg/commands/git_commands/git_command_builder.go b/pkg/commands/git_commands/git_command_builder.go index f1a7c87b4..43bcd7206 100644 --- a/pkg/commands/git_commands/git_command_builder.go +++ b/pkg/commands/git_commands/git_command_builder.go @@ -19,12 +19,12 @@ import ( // that opts back in is the foreground files refresh; see FileLoader.gitStatus. const OptionalLocksEnvVar = "GIT_OPTIONAL_LOCKS" -// forOtherRepo prepares a command that operates on a repo other than the one +// ForOtherRepo prepares a command that operates on a repo other than the one // we have open — a submodule, or another worktree. GIT_DIR and GIT_WORK_TREE // say where our repo is, and every command we run inherits them, so a command // pointed at a different repo would be resolved against ours instead: `git -C // log` would silently log the superproject's commits. -func forOtherRepo(cmdObj *oscommands.CmdObj) *oscommands.CmdObj { +func ForOtherRepo(cmdObj *oscommands.CmdObj) *oscommands.CmdObj { return cmdObj.RemoveEnvVar(env.GitDirEnvVar).RemoveEnvVar(env.GitWorkTreeEnvVar) } diff --git a/pkg/commands/git_commands/repo_paths.go b/pkg/commands/git_commands/repo_paths.go index 0473f8f8e..088dd86b6 100644 --- a/pkg/commands/git_commands/repo_paths.go +++ b/pkg/commands/git_commands/repo_paths.go @@ -271,13 +271,13 @@ func callGitRevParseWithDir( return runGitRevParse(newGitRevParseCmd(cmd, dir, gitRevArgs...)) } -// Asks git about a repo that isn't the one we have open; see forOtherRepo. +// Asks git about a repo that isn't the one we have open; see ForOtherRepo. func callGitRevParseInOtherRepo( cmd oscommands.ICmdObjBuilder, dir string, gitRevArgs ...string, ) (string, error) { - return runGitRevParse(forOtherRepo(newGitRevParseCmd(cmd, dir, gitRevArgs...))) + return runGitRevParse(ForOtherRepo(newGitRevParseCmd(cmd, dir, gitRevArgs...))) } func newGitRevParseCmd( diff --git a/pkg/commands/git_commands/submodule.go b/pkg/commands/git_commands/submodule.go index 7400f0514..0fa5de9df 100644 --- a/pkg/commands/git_commands/submodule.go +++ b/pkg/commands/git_commands/submodule.go @@ -157,7 +157,7 @@ func (self *SubmoduleCommands) GetCommitSummary(path string, sha string) (string Config("log.showsignature=false"). ToArgv() - summary, err := forOtherRepo(self.cmd.New(cmdArgs)).DontLog().RunWithOutput() + summary, err := ForOtherRepo(self.cmd.New(cmdArgs)).DontLog().RunWithOutput() return strings.TrimSpace(summary), err } @@ -167,7 +167,7 @@ func (self *SubmoduleCommands) GetCommitSummary(path string, sha string) (string // caller then stages the submodule to record the resolution. func (self *SubmoduleCommands) CheckoutConflictCommit(path string, sha string) error { cmdArgs := NewGitCmd("checkout").Dir(path).Arg(sha).ToArgv() - return forOtherRepo(self.cmd.New(cmdArgs)).Run() + return ForOtherRepo(self.cmd.New(cmdArgs)).Run() } // ConflictSideLog returns a oneline log, run inside the submodule, of the commits @@ -179,7 +179,7 @@ func (self *SubmoduleCommands) ConflictSideLog(path string, side string, otherSi Arg("--oneline", "--color=always", otherSide+".."+side). ToArgv() - return forOtherRepo(self.cmd.New(cmdArgs)).DontLog().RunWithOutput() + return ForOtherRepo(self.cmd.New(cmdArgs)).DontLog().RunWithOutput() } func (self *SubmoduleCommands) Stash(submodule *models.SubmoduleConfig) error { @@ -195,7 +195,7 @@ func (self *SubmoduleCommands) Stash(submodule *models.SubmoduleConfig) error { Arg("--include-untracked"). ToArgv() - return forOtherRepo(self.cmd.New(cmdArgs)).Run() + return ForOtherRepo(self.cmd.New(cmdArgs)).Run() } func (self *SubmoduleCommands) Reset(submodule *models.SubmoduleConfig) error { @@ -229,7 +229,7 @@ func (self *SubmoduleCommands) UpdateAll() error { // need not be. func (self *SubmoduleCommands) runInParentModule(submodule *models.SubmoduleConfig, cmdObj *oscommands.CmdObj) error { if submodule.ParentModule != nil { - forOtherRepo(cmdObj.SetWd(submodule.ParentModule.FullPath())) + ForOtherRepo(cmdObj.SetWd(submodule.ParentModule.FullPath())) } return cmdObj.Run() } diff --git a/pkg/commands/git_commands/worktree.go b/pkg/commands/git_commands/worktree.go index 64748b878..938287270 100644 --- a/pkg/commands/git_commands/worktree.go +++ b/pkg/commands/git_commands/worktree.go @@ -51,7 +51,7 @@ func (self *WorktreeCommands) Delete(worktreePath string, force bool) error { func (self *WorktreeCommands) Detach(worktreePath string) error { cmdArgs := NewGitCmd("checkout").Arg("--detach").GitDir(filepath.Join(worktreePath, ".git")).ToArgv() - return forOtherRepo(self.cmd.New(cmdArgs)).Run() + return ForOtherRepo(self.cmd.New(cmdArgs)).Run() } func WorktreeForBranch(branch *models.Branch, worktrees []*models.Worktree) (*models.Worktree, bool) {