Skip to content

Commit

Permalink
git: support git-dir and work-tree
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Jan 31, 2024
1 parent 9e96040 commit 3905d62
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion completers/git_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 3905d62

Please sign in to comment.