From 15cc98e3c5a0d6e4a9ad4f567a2f4c87093435e4 Mon Sep 17 00:00:00 2001 From: aftix Date: Sat, 7 Dec 2024 13:43:34 -0600 Subject: [PATCH] jj_completer: updated for v0.24.0 - Removed deprecated commands * `jj merge` * `jj move` * `jj checkout` - Added `jj absorb` command - Added `jj util exec` command - Added `--allow-new` flag to `jj git push` - `jj duplicate` now takes `--destination`, `--insert-before`, and `--insert-after` flags - New revset function `fork_point` - Several commands now accept `-f`/`-t` shorthands for `--from`/`--to` --- completers/jj_completer/cmd/absorb.go | 37 +++++++++++++++++++ completers/jj_completer/cmd/checkout.go | 26 ------------- completers/jj_completer/cmd/diff.go | 4 +- completers/jj_completer/cmd/diffedit.go | 4 +- completers/jj_completer/cmd/duplicate.go | 19 ++++++++++ completers/jj_completer/cmd/git_push.go | 2 + completers/jj_completer/cmd/interdiff.go | 4 +- completers/jj_completer/cmd/merge.go | 27 -------------- completers/jj_completer/cmd/move.go | 34 ----------------- completers/jj_completer/cmd/operation_diff.go | 4 +- completers/jj_completer/cmd/restore.go | 4 +- completers/jj_completer/cmd/util_exec.go | 31 ++++++++++++++++ pkg/actions/tools/jj/rev.go | 1 + 13 files changed, 100 insertions(+), 97 deletions(-) create mode 100644 completers/jj_completer/cmd/absorb.go delete mode 100644 completers/jj_completer/cmd/checkout.go delete mode 100644 completers/jj_completer/cmd/merge.go delete mode 100644 completers/jj_completer/cmd/move.go create mode 100644 completers/jj_completer/cmd/util_exec.go diff --git a/completers/jj_completer/cmd/absorb.go b/completers/jj_completer/cmd/absorb.go new file mode 100644 index 0000000000..c592fd0c00 --- /dev/null +++ b/completers/jj_completer/cmd/absorb.go @@ -0,0 +1,37 @@ +package cmd + +import ( + "github.com/carapace-sh/carapace" + "github.com/carapace-sh/carapace-bin/pkg/actions/tools/jj" + "github.com/spf13/cobra" +) + +var absorbCmd = &cobra.Command{ + Use: "absorb [OPTIONS] [PATHS]...", + Short: "Move changes from a revision into the stack of mutable revisions", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(absorbCmd).Standalone() + + absorbCmd.Flags().StringP("from", "f", "@", "Source revision to absorb from") + absorbCmd.Flags().BoolP("help", "h", false, "Print help (see more with '--help')") + absorbCmd.Flags().StringP("into", "t", "mutable()", "Destination revisions to absorb into") + absorbCmd.Flags().String("to", "mutable()", "Alias for --into") + rootCmd.AddCommand(absorbCmd) + + absorbCmd.MarkFlagsMutuallyExclusive("into", "to") + + carapace.Gen(absorbCmd).FlagCompletion(carapace.ActionMap{ + "from": jj.ActionRevs(jj.RevOption{}.Default()), + "into": jj.ActionRevs(jj.RevOption{}.Default()), + "to": jj.ActionRevs(jj.RevOption{}.Default()), + }) + + carapace.Gen(absorbCmd).PositionalAnyCompletion( + carapace.ActionCallback(func(carapace.Context) carapace.Action { + return jj.ActionRevFiles(absorbCmd.Flag("from").Value.String()) + }), + ) +} diff --git a/completers/jj_completer/cmd/checkout.go b/completers/jj_completer/cmd/checkout.go deleted file mode 100644 index caba3b237b..0000000000 --- a/completers/jj_completer/cmd/checkout.go +++ /dev/null @@ -1,26 +0,0 @@ -package cmd - -import ( - "github.com/carapace-sh/carapace" - "github.com/carapace-sh/carapace-bin/pkg/actions/tools/jj" - "github.com/spf13/cobra" -) - -var checkoutCmd = &cobra.Command{ - Use: "checkout [OPTIONS] ", - Short: "Create a new, empty change and edit it in the working copy", - Aliases: []string{"co"}, - Run: func(cmd *cobra.Command, args []string) {}, -} - -func init() { - carapace.Gen(checkoutCmd).Standalone() - - checkoutCmd.Flags().BoolP("help", "h", false, "Print help (see more with '--help')") - checkoutCmd.Flags().StringSliceP("message", "m", []string{}, "The change description to use") - rootCmd.AddCommand(checkoutCmd) - - carapace.Gen(checkoutCmd).PositionalCompletion( - jj.ActionRevs(jj.RevOption{}.Default()), - ) -} diff --git a/completers/jj_completer/cmd/diff.go b/completers/jj_completer/cmd/diff.go index c3d945e612..754eeff8ea 100644 --- a/completers/jj_completer/cmd/diff.go +++ b/completers/jj_completer/cmd/diff.go @@ -18,7 +18,7 @@ func init() { diffCmd.Flags().Int("context", 3, "Number of lines of context to show") diffCmd.Flags().Bool("color-words", false, "Show a word-level diff with changes indicated only by color") - diffCmd.Flags().String("from", "", "Show changes from this revision") + diffCmd.Flags().StringP("from", "-f", "", "Show changes from this revision") diffCmd.Flags().Bool("git", false, "Show a Git-format diff") diffCmd.Flags().BoolP("help", "h", false, "Print help (see more with '--help')") diffCmd.Flags().BoolP("ignore-all-space", "w", false, "Ignore whitespace when comparing lines") @@ -27,7 +27,7 @@ func init() { diffCmd.Flags().StringP("revision", "r", "", "Show changes in this revision, compared to its parent(s)") diffCmd.Flags().Bool("stat", false, "Show a histogram of the changes") diffCmd.Flags().BoolP("summary", "s", false, "For each path, show only whether it was modified, added, or removed") - diffCmd.Flags().String("to", "", "Show changes to this revision") + diffCmd.Flags().StringP("to", "t", "", "Show changes to this revision") diffCmd.Flags().String("tool", "", "Generate diff by external command") diffCmd.Flags().Bool("types", false, "For each path, show only its type before and after") rootCmd.AddCommand(diffCmd) diff --git a/completers/jj_completer/cmd/diffedit.go b/completers/jj_completer/cmd/diffedit.go index ff52abc3e7..737e76bbcc 100644 --- a/completers/jj_completer/cmd/diffedit.go +++ b/completers/jj_completer/cmd/diffedit.go @@ -15,11 +15,11 @@ var diffeditCmd = &cobra.Command{ func init() { carapace.Gen(diffeditCmd).Standalone() - diffeditCmd.Flags().String("from", "@", "Show changes from this revision. Defaults to @ if --to is specified") + diffeditCmd.Flags().StringP("from", "f", "@", "Show changes from this revision. Defaults to @ if --to is specified") diffeditCmd.Flags().BoolP("help", "h", false, "Print help (see more with '--help')") diffeditCmd.Flags().Bool("restore-descendants", false, "Preserve the content (not the diff) when rebasing descendants") diffeditCmd.Flags().StringP("revision", "r", "@", "The revision to touch up. Defaults to @ if neither --to nor --from are specified") - diffeditCmd.Flags().String("to", "@", "Edit changes in this revision. Defaults to @ if --from is specified") + diffeditCmd.Flags().StringP("to", "t", "@", "Edit changes in this revision. Defaults to @ if --from is specified") rootCmd.AddCommand(diffeditCmd) carapace.Gen(diffeditCmd).FlagCompletion(carapace.ActionMap{ diff --git a/completers/jj_completer/cmd/duplicate.go b/completers/jj_completer/cmd/duplicate.go index 0f9a5207fa..78e728aa02 100644 --- a/completers/jj_completer/cmd/duplicate.go +++ b/completers/jj_completer/cmd/duplicate.go @@ -15,9 +15,28 @@ var duplicateCmd = &cobra.Command{ func init() { carapace.Gen(duplicateCmd).Standalone() + duplicateCmd.Flags().StringArray("after", []string{}, "Alias for --insert-after") + duplicateCmd.Flags().StringArray("before", []string{}, "Alias for --insert-before") + duplicateCmd.Flags().StringArrayP("destination", "d", []string{"@"}, "The revision(s) to duplicate onto (can be repeated to create a merge commit)") duplicateCmd.Flags().BoolP("help", "h", false, "Print help (see more with '--help')") + duplicateCmd.Flags().StringArrayP("insert-after", "A", []string{}, "The revision(s) to insert after (can be repeated to create a merge commit)") + duplicateCmd.Flags().StringArrayP("insert-before", "B", []string{}, "The revision(s) to insert before (can be repeated to create a merge commit)") rootCmd.AddCommand(duplicateCmd) + duplicateCmd.MarkFlagsMutuallyExclusive( + "after", + "before", + "destination", + "insert-after", + "insert-before", + ) + + carapace.Gen(duplicateCmd).FlagCompletion(carapace.ActionMap{ + "destination": jj.ActionRevs(jj.RevOption{}.Default()), + "insert-after": jj.ActionRevs(jj.RevOption{}.Default()), + "insert-before": jj.ActionRevs(jj.RevOption{}.Default()), + }) + carapace.Gen(duplicateCmd).PositionalAnyCompletion( jj.ActionRevs(jj.RevOption{}.Default()).FilterArgs(), ) diff --git a/completers/jj_completer/cmd/git_push.go b/completers/jj_completer/cmd/git_push.go index 139104cd6c..b7d6d73119 100644 --- a/completers/jj_completer/cmd/git_push.go +++ b/completers/jj_completer/cmd/git_push.go @@ -17,6 +17,8 @@ func init() { git_pushCmd.Flags().Bool("all", false, "Push all bookmarks (including deleted bookmarks)") git_pushCmd.Flags().Bool("allow-empty-description", false, "Allow commits with empty description messages to be pushed") + git_pushCmd.Flags().BoolP("allow-new", "N", false, "Allow pushing new bookmarks") + git_pushCmd.Flags().Bool("allow-private", false, "Allow pushing commits that are private") git_pushCmd.Flags().StringSliceP("bookmark", "b", []string{}, "Push only this bookmark (can be repeated)") git_pushCmd.Flags().StringSliceP("change", "c", []string{}, "Push this commit by creating a bookmark based on its change ID (can be repeated)") git_pushCmd.Flags().Bool("deleted", false, "Push all deleted bookmarks") diff --git a/completers/jj_completer/cmd/interdiff.go b/completers/jj_completer/cmd/interdiff.go index b3b944e536..6090062d98 100644 --- a/completers/jj_completer/cmd/interdiff.go +++ b/completers/jj_completer/cmd/interdiff.go @@ -18,12 +18,12 @@ func init() { interdiffCmd.Flags().Int("context", 3, "Number of lines of context to show") interdiffCmd.Flags().Bool("color-words", false, "Show a word-level diff with changes indicated only by color") - interdiffCmd.Flags().String("from", "@", "Show changes from this revision") + interdiffCmd.Flags().StringP("from", "f", "@", "Show changes from this revision") interdiffCmd.Flags().Bool("git", false, "Show a Git-format diff") interdiffCmd.Flags().BoolP("help", "h", false, "Print help (see more with '--help')") interdiffCmd.Flags().Bool("stat", false, "Show a histogram of the changes") interdiffCmd.Flags().BoolP("summary", "s", false, "For each path, show only whether it was modified, added, or removed") - interdiffCmd.Flags().String("to", "@", "Show changes to this revision") + interdiffCmd.Flags().StringP("to", "t", "@", "Show changes to this revision") interdiffCmd.Flags().String("tool", "", "Generate diff by external command") interdiffCmd.Flags().Bool("types", false, "For each path, show only its type before and after") rootCmd.AddCommand(interdiffCmd) diff --git a/completers/jj_completer/cmd/merge.go b/completers/jj_completer/cmd/merge.go deleted file mode 100644 index ea7882b9eb..0000000000 --- a/completers/jj_completer/cmd/merge.go +++ /dev/null @@ -1,27 +0,0 @@ -package cmd - -import ( - "github.com/carapace-sh/carapace" - "github.com/carapace-sh/carapace-bin/pkg/actions/tools/jj" - "github.com/spf13/cobra" -) - -var mergeCmd = &cobra.Command{ - Use: "merge [OPTIONS] [REVISIONS]...", - Short: "Merge work from multiple bookmarks", - Run: func(cmd *cobra.Command, args []string) {}, -} - -func init() { - carapace.Gen(mergeCmd).Standalone() - - mergeCmd.Flags().BoolP("help", "h", false, "Print help (see more with '--help')") - mergeCmd.Flags().BoolP("insert-after", "A", false, "Insert the new change between the target commit(s) and their children") - mergeCmd.Flags().BoolP("insert-before", "B", false, "Insert the new change between the target commit(s) and their parents") - mergeCmd.Flags().StringSliceP("message", "m", []string{}, "The change description to use") - rootCmd.AddCommand(mergeCmd) - - carapace.Gen(mergeCmd).PositionalAnyCompletion( - jj.ActionRevs(jj.RevOption{}.Default()).FilterArgs(), - ) -} diff --git a/completers/jj_completer/cmd/move.go b/completers/jj_completer/cmd/move.go deleted file mode 100644 index 98064e7979..0000000000 --- a/completers/jj_completer/cmd/move.go +++ /dev/null @@ -1,34 +0,0 @@ -package cmd - -import ( - "github.com/carapace-sh/carapace" - "github.com/carapace-sh/carapace-bin/pkg/actions/tools/jj" - "github.com/spf13/cobra" -) - -var moveCmd = &cobra.Command{ - Use: "move [OPTIONS] <--from |--to > [PATHS]...", - Short: "Move changes from one revision into another", - Run: func(cmd *cobra.Command, args []string) {}, -} - -func init() { - carapace.Gen(moveCmd).Standalone() - - moveCmd.Flags().String("from", "@", "Move part of this change into the destination") - moveCmd.Flags().BoolP("help", "h", false, "Print help (see more with '--help')") - moveCmd.Flags().BoolP("interactive", "i", false, "Interactively choose which parts to move") - moveCmd.Flags().String("to", "@", "Move part of the source into this change") - rootCmd.AddCommand(moveCmd) - - carapace.Gen(moveCmd).FlagCompletion(carapace.ActionMap{ - "from": jj.ActionRevs(jj.RevOption{}.Default()), - "to": jj.ActionRevs(jj.RevOption{}.Default()), - }) - - carapace.Gen(moveCmd).PositionalAnyCompletion( - carapace.ActionCallback(func(c carapace.Context) carapace.Action { - return jj.ActionRevChanges(moveCmd.Flag("from").Value.String()).FilterArgs() - }), - ) -} diff --git a/completers/jj_completer/cmd/operation_diff.go b/completers/jj_completer/cmd/operation_diff.go index b05fd9b641..338195487a 100644 --- a/completers/jj_completer/cmd/operation_diff.go +++ b/completers/jj_completer/cmd/operation_diff.go @@ -17,10 +17,10 @@ func init() { carapace.Gen(operation_diffCmd).Standalone() // Options - operation_diffCmd.Flags().String("from", "", "Show repository changes from this operation") + operation_diffCmd.Flags().StringP("from", "f", "", "Show repository changes from this operation") operation_diffCmd.Flags().Bool("no-graph", false, "Don't show the graph, show a flat list of operations") operation_diffCmd.Flags().String("operation", "", "Show repository changes in this operation, compared to its parent") - operation_diffCmd.Flags().String("to", "", "Show repository changes to this operation") + operation_diffCmd.Flags().StringP("to", "t", "", "Show repository changes to this operation") // Diff formatting options operation_diffCmd.Flags().Int("context", 3, "Number of lines of context to show") diff --git a/completers/jj_completer/cmd/restore.go b/completers/jj_completer/cmd/restore.go index 62e18ea172..5906bfb10e 100644 --- a/completers/jj_completer/cmd/restore.go +++ b/completers/jj_completer/cmd/restore.go @@ -16,10 +16,10 @@ func init() { carapace.Gen(restoreCmd).Standalone() restoreCmd.Flags().StringP("changes-in", "c", "", "Undo the changes in a revision as compared to the merge of its parents") - restoreCmd.Flags().String("from", "@", "Revision to restore from (source)") + restoreCmd.Flags().StringP("from", "f", "@", "Revision to restore from (source)") restoreCmd.Flags().BoolP("help", "h", false, "Print help (see more with '--help')") restoreCmd.Flags().Bool("restore-descendants", false, "Preserve the content (not the diff) when rebasing descendants") - restoreCmd.Flags().String("to", "@", "Revision to restore into (destination)") + restoreCmd.Flags().StringP("to", "t", "@", "Revision to restore into (destination)") rootCmd.AddCommand(restoreCmd) carapace.Gen(restoreCmd).FlagCompletion(carapace.ActionMap{ diff --git a/completers/jj_completer/cmd/util_exec.go b/completers/jj_completer/cmd/util_exec.go new file mode 100644 index 0000000000..d095764c7b --- /dev/null +++ b/completers/jj_completer/cmd/util_exec.go @@ -0,0 +1,31 @@ +package cmd + +import ( + "github.com/carapace-sh/carapace" + "github.com/carapace-sh/carapace-bridge/pkg/actions/bridge" + "github.com/spf13/cobra" +) + +var util_execCmd = &cobra.Command{ + Use: "exec", + Short: "Execute an external command via jj", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(util_execCmd).Standalone() + + util_execCmd.Flags().BoolP("help", "h", false, "Print help (see more with '--help')") + utilCmd.AddCommand(util_execCmd) + + carapace.Gen(util_execCmd).PositionalCompletion( + carapace.Batch( + carapace.ActionExecutables(), + carapace.ActionFiles(), + ).ToA(), + ) + + carapace.Gen(util_execCmd).PositionalAnyCompletion( + bridge.ActionCarapaceBin(), + ) +} diff --git a/pkg/actions/tools/jj/rev.go b/pkg/actions/tools/jj/rev.go index 87a829a7d8..e076c34b50 100644 --- a/pkg/actions/tools/jj/rev.go +++ b/pkg/actions/tools/jj/rev.go @@ -110,5 +110,6 @@ func ActionRevSetFunctions() carapace.Action { "untracked_remote_bookmarks", "All targets of untracked remote bookmarks", "coalesce", "Get first non-none revset from a list of revsets", "at_operation", "Query revisions based on historical state", + "fork_point", "Obtain the fork point of multiple commits", ).Tag("revset functions") }