From eb988395e6d1caaac40a0dfbeb2cf259fb2889b0 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Fri, 19 Jun 2026 17:40:51 +0200 Subject: [PATCH] Remove the now-redundant gitCmdObjBuilder wrapper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The wrapper existed to add a git-specific env var to every command. Now that that's gone, its New/NewShell/Quote methods just delegated to the inner builder. The only remaining git-specific behavior — the command runner — is attached in the constructor via CloneWithNewRunner, which already returns a complete builder, so we can return that directly and drop the wrapper struct. Co-Authored-By: Claude Opus 4.8 (1M context) --- pkg/commands/git_cmd_obj_builder.go | 35 ++++++----------------------- 1 file changed, 7 insertions(+), 28 deletions(-) diff --git a/pkg/commands/git_cmd_obj_builder.go b/pkg/commands/git_cmd_obj_builder.go index 495582722..6b6bd26d8 100644 --- a/pkg/commands/git_cmd_obj_builder.go +++ b/pkg/commands/git_cmd_obj_builder.go @@ -5,37 +5,16 @@ import ( "github.com/sirupsen/logrus" ) -// all we're doing here is wrapping the default command object builder with -// some git-specific stuff: e.g. adding a git-specific env var - -type gitCmdObjBuilder struct { - innerBuilder *oscommands.CmdObjBuilder -} - -var _ oscommands.ICmdObjBuilder = &gitCmdObjBuilder{} - -func NewGitCmdObjBuilder(log *logrus.Entry, innerBuilder *oscommands.CmdObjBuilder) *gitCmdObjBuilder { - // the price of having a convenient interface where we can say .New(...).Run() is that our builder now depends on our runner, so when we want to wrap the default builder/runner in new functionality we need to jump through some hoops. We could avoid the use of a decorator function here by just exporting the runner field on the default builder but that would be misleading because we don't want anybody using that to run commands (i.e. we want there to be a single API used across the codebase) - updatedBuilder := innerBuilder.CloneWithNewRunner(func(runner oscommands.ICmdObjRunner) oscommands.ICmdObjRunner { +// NewGitCmdObjBuilder returns a command object builder whose runner is wrapped +// with our git-specific runner (logging, credential handling, etc.). +func NewGitCmdObjBuilder(log *logrus.Entry, innerBuilder *oscommands.CmdObjBuilder) *oscommands.CmdObjBuilder { + // We decorate the runner rather than exposing the builder's runner field: + // that field stays unexported so there's a single API for running commands + // across the codebase. + return innerBuilder.CloneWithNewRunner(func(runner oscommands.ICmdObjRunner) oscommands.ICmdObjRunner { return &gitCmdObjRunner{ log: log, innerRunner: runner, } }) - - return &gitCmdObjBuilder{ - innerBuilder: updatedBuilder, - } -} - -func (self *gitCmdObjBuilder) New(args []string) *oscommands.CmdObj { - return self.innerBuilder.New(args) -} - -func (self *gitCmdObjBuilder) NewShell(cmdStr string, shellFunctionsFile string) *oscommands.CmdObj { - return self.innerBuilder.NewShell(cmdStr, shellFunctionsFile) -} - -func (self *gitCmdObjBuilder) Quote(str string) string { - return self.innerBuilder.Quote(str) }