From 3905d6202ddaf508a529a9379f9738ab89026722 Mon Sep 17 00:00:00 2001 From: rsteube Date: Wed, 31 Jan 2024 12:17:19 +0100 Subject: [PATCH] git: support git-dir and work-tree --- completers/git_completer/cmd/root.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/completers/git_completer/cmd/root.go b/completers/git_completer/cmd/root.go index 528fea60f3..de6d0e196b 100644 --- a/completers/git_completer/cmd/root.go +++ b/completers/git_completer/cmd/root.go @@ -89,7 +89,19 @@ func init() { }) carapace.Gen(rootCmd).PreInvoke(func(cmd *cobra.Command, flag *pflag.Flag, action carapace.Action) carapace.Action { - return action.Chdir(rootCmd.Flag("C").Value.String()) + return carapace.ActionCallback(func(c carapace.Context) carapace.Action { + if f := rootCmd.Flag("git-dir"); f.Changed { + c.Setenv("GIT_DIR", f.Value.String()) + } + if f := rootCmd.Flag("work-tree"); f.Changed { + c.Setenv("GIT_WORK_TREE", f.Value.String()) + action = action.Chdir(f.Value.String()) + } + if f := rootCmd.Flag("C"); f.Changed { + action = action.Chdir(f.Value.String()) + } + return action.Invoke(c).ToA() + }) }) carapace.Gen(rootCmd).PreRun(func(cmd *cobra.Command, args []string) {