Skip to content

Commit

Permalink
Merge pull request #134 from rsteube/add-git-push
Browse files Browse the repository at this point in the history
added git push
  • Loading branch information
rsteube authored Sep 12, 2020
2 parents b999130 + 2621604 commit 9c00c6e
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
10 changes: 10 additions & 0 deletions completers/git_completer/cmd/action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ func ActionRemoteBranches(remote string) carapace.Action {
})
}

func ActionCurrentBranch() carapace.Action {
return carapace.ActionCallback(func(args []string) carapace.Action {
if output, err := exec.Command("git", "branch", "--show-current").Output(); err != nil {
return carapace.ActionMessage(err.Error())
} else {
return carapace.ActionValues(strings.Split(string(output), "\n")[0])
}
})
}

type RefOption struct {
LocalBranches bool
RemoteBranches bool
Expand Down
60 changes: 60 additions & 0 deletions completers/git_completer/cmd/push.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/git_completer/cmd/action"
"github.com/spf13/cobra"
)

var pushCmd = &cobra.Command{
Use: "push",
Short: "Update remote refs along with associated objects",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(pushCmd).Standalone()

pushCmd.Flags().Bool("all", false, "push all refs")
pushCmd.Flags().Bool("atomic", false, "request atomic transaction on remote side")
pushCmd.Flags().BoolP("delete", "d", false, "delete refs")
pushCmd.Flags().BoolP("dry-run", "n", false, "dry run")
pushCmd.Flags().String("exec", "", "receive pack program")
pushCmd.Flags().Bool("follow-tags", false, "push missing but relevant tags")
pushCmd.Flags().BoolP("force", "f", false, "force updates")
pushCmd.Flags().String("force-with-lease", "", "require old value of ref to be at this value")
pushCmd.Flags().BoolP("ipv4", "4", false, "use IPv4 addresses only")
pushCmd.Flags().BoolP("ipv6", "6", false, "use IPv6 addresses only")
pushCmd.Flags().Bool("mirror", false, "mirror all refs")
pushCmd.Flags().Bool("no-verify", false, "bypass pre-push hook")
pushCmd.Flags().Bool("porcelain", false, "machine-readable output")
pushCmd.Flags().Bool("progress", false, "force progress reporting")
pushCmd.Flags().Bool("prune", false, "prune locally removed refs")
pushCmd.Flags().StringP("push-option", "o", "", "option to transmit")
pushCmd.Flags().BoolP("quiet", "q", false, "be more quiet")
pushCmd.Flags().String("receive-pack", "", "receive pack program")
pushCmd.Flags().String("recurse-submodules", "", "control recursive pushing of submodules")
pushCmd.Flags().String("repo", "", "repository")
pushCmd.Flags().BoolP("set-upstream", "u", false, "set upstream for git pull/status")
pushCmd.Flags().String("signed", "", "GPG sign the push")
pushCmd.Flags().Bool("tags", false, "push tags (can't be used with --all or --mirror)")
pushCmd.Flags().Bool("thin", false, "use thin pack")
pushCmd.Flags().BoolP("verbose", "v", false, "be more verbose")
rootCmd.AddCommand(pushCmd)

carapace.Gen(pushCmd).FlagCompletion(carapace.ActionMap{
"signed": carapace.ActionValues("yes", "no", "if-asked"),
})

carapace.Gen(pushCmd).PositionalCompletion(
action.ActionRemotes(),
carapace.ActionCallback(func(args []string) carapace.Action {
if pushCmd.Flag("set-upstream").Changed {
// if set-upstream is set the desired remote branch is likely named the same as the current
return action.ActionCurrentBranch()
} else {
return action.ActionRemoteBranches(args[0])
}
}),
)
}

0 comments on commit 9c00c6e

Please sign in to comment.