Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git: suggest local branches for push #2249

Merged
merged 2 commits into from
Feb 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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])
}
})
}),
)
}
Loading