Skip to content

Commit

Permalink
Merge pull request #2210 from rsteube/git-dir-and-worktree
Browse files Browse the repository at this point in the history
git: support git-dir and work-tree
  • Loading branch information
rsteube authored Jan 31, 2024
2 parents e859207 + 3905d62 commit ac2a2a0
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 ac2a2a0

Please sign in to comment.