-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
164 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 39 additions & 9 deletions
48
...s/git_completer/cmd/checkout_generated.go → completers/git_completer/cmd/checkout.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,68 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/rsteube/carapace" | ||
"github.com/rsteube/carapace-bin/completers/git_completer/cmd/action" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var checkoutCmd = &cobra.Command{ | ||
Use: "checkout", | ||
Short: "Switch branches or restore working tree files", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
}, | ||
Run: func(cmd *cobra.Command, args []string) {}, | ||
} | ||
|
||
func init() { | ||
checkoutCmd.Flags().BoolP("ours", "2", false, "checkout our version for unmerged files") | ||
checkoutCmd.Flags().BoolP("theirs", "3", false, "checkout their version for unmerged files") | ||
checkoutCmd.Flags().StringP("b", "b", "", "create and checkout a new branch") | ||
checkoutCmd.Flags().StringP("B", "B", "", "create/reset and checkout a branch") | ||
carapace.Gen(checkoutCmd).Standalone() | ||
|
||
checkoutCmd.Flags().StringS("b", "b", "", "create and checkout a new branch") | ||
checkoutCmd.Flags().StringS("B", "B", "", "create/reset and checkout a branch") | ||
checkoutCmd.Flags().BoolS("l", "l", false, "create reflog for new branch") | ||
checkoutCmd.Flags().String("conflict", "", "conflict style (merge or diff3)") | ||
checkoutCmd.Flags().BoolP("detach", "d", false, "detach HEAD at named commit") | ||
checkoutCmd.Flags().BoolP("force", "f", false, "force checkout (throw away local modifications)") | ||
checkoutCmd.Flags().Bool("guess", false, "second guess 'git checkout <no-such-branch>' (default)") | ||
checkoutCmd.Flags().Bool("ignore-other-worktrees", false, "do not check if another worktree is holding the given ref") | ||
checkoutCmd.Flags().Bool("ignore-skip-worktree-bits", false, "do not limit pathspecs to sparse entries only") | ||
checkoutCmd.Flags().BoolP("l", "l", false, "create reflog for new branch") | ||
checkoutCmd.Flags().BoolP("merge", "m", false, "perform a 3-way merge with the new branch") | ||
checkoutCmd.Flags().String("orphan", "", "new unparented branch") | ||
checkoutCmd.Flags().BoolP("ours", "2", false, "checkout our version for unmerged files") | ||
checkoutCmd.Flags().Bool("overlay", false, "use overlay mode (default)") | ||
checkoutCmd.Flags().Bool("overwrite-ignore", false, "update ignored files (default)") | ||
checkoutCmd.Flags().Bool("pathspec-file-nul", false, "with --pathspec-from-file, pathspec elements are separated with NUL character") | ||
checkoutCmd.Flags().String("pathspec-from-file", "", "read pathspec from file") | ||
checkoutCmd.Flags().BoolP("patch", "p", false, "select hunks interactively") | ||
checkoutCmd.Flags().Bool("pathspec-file-nul", false, "pathspec elements are separated with NUL character") | ||
checkoutCmd.Flags().String("pathspec-from-file", "", "read pathspec from file") | ||
checkoutCmd.Flags().Bool("progress", false, "force progress reporting") | ||
checkoutCmd.Flags().BoolP("quiet", "q", false, "suppress progress reporting") | ||
checkoutCmd.Flags().String("recurse-submodules", "", "control recursive updating of submodules") | ||
checkoutCmd.Flags().BoolP("theirs", "3", false, "checkout their version for unmerged files") | ||
checkoutCmd.Flags().BoolP("track", "t", false, "set upstream info for new branch") | ||
rootCmd.AddCommand(checkoutCmd) | ||
|
||
carapace.Gen(checkoutCmd).FlagCompletion(carapace.ActionMap{ | ||
"b": action.ActionRefs(action.RefOption{LocalBranches: true}), | ||
"B": action.ActionRefs(action.RefOption{LocalBranches: true}), | ||
"conflict": carapace.ActionValues("merge", "diff3"), | ||
"orphan": action.ActionRefs(action.RefOption{LocalBranches: true, RemoteBranches: true}), | ||
"pathspec-from-file": carapace.ActionFiles(""), | ||
}) | ||
|
||
carapace.Gen(checkoutCmd).PositionalCompletion( | ||
action.ActionRefs(action.RefOptionDefault), | ||
) | ||
|
||
carapace.Gen(checkoutCmd).PositionalAnyCompletion( | ||
carapace.ActionCallback(func(args []string) carapace.Action { | ||
// the first `--` is currently not detected as positional argument, | ||
// so just search the full command line for it and assume it's the divider | ||
for _, arg := range os.Args { | ||
if arg == "--" { | ||
return carapace.ActionFiles("") // TODO files from branch? | ||
} | ||
} | ||
return carapace.ActionValues() | ||
}), | ||
) | ||
} |