Skip to content

Commit

Permalink
Merge pull request #2249 from Trojan295/fix/push-use-local-branches
Browse files Browse the repository at this point in the history
git: suggest local branches for push
  • Loading branch information
rsteube authored Feb 18, 2024
2 parents 3ee6a55 + 8d138e4 commit 7c9fcae
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions completers/git_completer/cmd/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,23 @@ func init() {
carapace.Gen(pushCmd).PositionalCompletion(
git.ActionRemotes(),
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if pushCmd.Flag("set-upstream").Changed {
if pushCmd.Flag("set-upstream").Changed && c.Value == "" {
// if set-upstream is set the desired remote branch is likely named the same as the current
return git.ActionCurrentBranch()
} else {
return git.ActionRemoteBranches(c.Args[0])
}

return carapace.ActionMultiPartsN(":", 2, func(c carapace.Context) carapace.Action {
switch len(c.Parts) {
case 0:
return git.ActionRefs(git.RefOption{
LocalBranches: true,
HeadCommits: 1,
Tags: true,
}).NoSpace()
default:
return git.ActionRemoteBranchNames(c.Args[0])
}
})
}),
)
}

0 comments on commit 7c9fcae

Please sign in to comment.