diff --git a/cli/src/commands/debug/mod.rs b/cli/src/commands/debug/mod.rs index d10de1c25f..f7fb4ed7a0 100644 --- a/cli/src/commands/debug/mod.rs +++ b/cli/src/commands/debug/mod.rs @@ -48,18 +48,17 @@ use crate::ui::Ui; #[command(hide = true)] pub enum DebugCommand { Fileset(FilesetArgs), - Revset(RevsetArgs), - #[command(name = "workingcopy")] - WorkingCopy(WorkingCopyArgs), - Template(TemplateArgs), Index(IndexArgs), - Reindex(ReindexArgs), #[command(visible_alias = "view")] Operation(OperationArgs), + Reindex(ReindexArgs), + Revset(RevsetArgs), + Snapshot(SnapshotArgs), + Template(TemplateArgs), Tree(TreeArgs), #[command(subcommand)] Watchman(WatchmanCommand), - Snapshot(SnapshotArgs), + WorkingCopy(WorkingCopyArgs), } pub fn cmd_debug( @@ -69,15 +68,15 @@ pub fn cmd_debug( ) -> Result<(), CommandError> { match subcommand { DebugCommand::Fileset(args) => cmd_debug_fileset(ui, command, args), - DebugCommand::Revset(args) => cmd_debug_revset(ui, command, args), - DebugCommand::WorkingCopy(args) => cmd_debug_working_copy(ui, command, args), - DebugCommand::Template(args) => cmd_debug_template(ui, command, args), DebugCommand::Index(args) => cmd_debug_index(ui, command, args), - DebugCommand::Reindex(args) => cmd_debug_reindex(ui, command, args), DebugCommand::Operation(args) => cmd_debug_operation(ui, command, args), + DebugCommand::Reindex(args) => cmd_debug_reindex(ui, command, args), + DebugCommand::Revset(args) => cmd_debug_revset(ui, command, args), + DebugCommand::Snapshot(args) => cmd_debug_snapshot(ui, command, args), + DebugCommand::Template(args) => cmd_debug_template(ui, command, args), DebugCommand::Tree(args) => cmd_debug_tree(ui, command, args), DebugCommand::Watchman(args) => cmd_debug_watchman(ui, command, args), - DebugCommand::Snapshot(args) => cmd_debug_snapshot(ui, command, args), + DebugCommand::WorkingCopy(args) => cmd_debug_working_copy(ui, command, args), } } diff --git a/cli/src/commands/git/mod.rs b/cli/src/commands/git/mod.rs index 4df07d0bbd..53fb21bd61 100644 --- a/cli/src/commands/git/mod.rs +++ b/cli/src/commands/git/mod.rs @@ -43,18 +43,35 @@ use crate::ui::Ui; /// https://github.com/martinvonz/jj/blob/main/docs/git-comparison.md. #[derive(Subcommand, Clone, Debug)] pub enum GitCommand { - #[command(subcommand)] - Remote(RemoteCommand), - Init(InitArgs), - Fetch(FetchArgs), Clone(CloneArgs), - Push(PushArgs), - Import(ImportArgs), Export(ExportArgs), + Fetch(FetchArgs), + Import(ImportArgs), + Init(InitArgs), + Push(PushArgs), + #[command(subcommand)] + Remote(RemoteCommand), #[command(subcommand, hide = true)] Submodule(SubmoduleCommand), } +pub fn cmd_git( + ui: &mut Ui, + command: &CommandHelper, + subcommand: &GitCommand, +) -> Result<(), CommandError> { + match subcommand { + GitCommand::Clone(args) => cmd_git_clone(ui, command, args), + GitCommand::Export(args) => cmd_git_export(ui, command, args), + GitCommand::Fetch(args) => cmd_git_fetch(ui, command, args), + GitCommand::Import(args) => cmd_git_import(ui, command, args), + GitCommand::Init(args) => cmd_git_init(ui, command, args), + GitCommand::Push(args) => cmd_git_push(ui, command, args), + GitCommand::Remote(args) => cmd_git_remote(ui, command, args), + GitCommand::Submodule(args) => cmd_git_submodule(ui, command, args), + } +} + fn map_git_error(err: git2::Error) -> CommandError { if err.class() == git2::ErrorClass::Ssh { let hint = @@ -95,20 +112,3 @@ fn get_single_remote(git_repo: &git2::Repository) -> Result, Comm _ => None, }) } - -pub fn cmd_git( - ui: &mut Ui, - command: &CommandHelper, - subcommand: &GitCommand, -) -> Result<(), CommandError> { - match subcommand { - GitCommand::Init(args) => cmd_git_init(ui, command, args), - GitCommand::Fetch(args) => cmd_git_fetch(ui, command, args), - GitCommand::Clone(args) => cmd_git_clone(ui, command, args), - GitCommand::Remote(args) => cmd_git_remote(ui, command, args), - GitCommand::Push(args) => cmd_git_push(ui, command, args), - GitCommand::Import(args) => cmd_git_import(ui, command, args), - GitCommand::Export(args) => cmd_git_export(ui, command, args), - GitCommand::Submodule(args) => cmd_git_submodule(ui, command, args), - } -} diff --git a/cli/src/commands/git/remote/mod.rs b/cli/src/commands/git/remote/mod.rs index 617673e915..3026803ddc 100644 --- a/cli/src/commands/git/remote/mod.rs +++ b/cli/src/commands/git/remote/mod.rs @@ -33,9 +33,9 @@ use crate::ui::Ui; #[derive(Subcommand, Clone, Debug)] pub enum RemoteCommand { Add(AddArgs), + List(ListArgs), Remove(RemoveArgs), Rename(RenameArgs), - List(ListArgs), } pub fn cmd_git_remote( @@ -45,8 +45,8 @@ pub fn cmd_git_remote( ) -> Result<(), CommandError> { match subcommand { RemoteCommand::Add(args) => cmd_remote_add(ui, command, args), + RemoteCommand::List(args) => cmd_remote_list(ui, command, args), RemoteCommand::Remove(args) => cmd_remote_remove(ui, command, args), RemoteCommand::Rename(args) => cmd_remote_rename(ui, command, args), - RemoteCommand::List(args) => cmd_remote_list(ui, command, args), } } diff --git a/cli/tests/cli-reference@.md.snap b/cli/tests/cli-reference@.md.snap index d0d36cf2ac..91f4d73e21 100644 --- a/cli/tests/cli-reference@.md.snap +++ b/cli/tests/cli-reference@.md.snap @@ -41,17 +41,17 @@ This document contains the help content for the `jj` command-line program. * [`jj file print`↴](#jj-file-print) * [`jj fix`↴](#jj-fix) * [`jj git`↴](#jj-git) +* [`jj git clone`↴](#jj-git-clone) +* [`jj git export`↴](#jj-git-export) +* [`jj git fetch`↴](#jj-git-fetch) +* [`jj git import`↴](#jj-git-import) +* [`jj git init`↴](#jj-git-init) +* [`jj git push`↴](#jj-git-push) * [`jj git remote`↴](#jj-git-remote) * [`jj git remote add`↴](#jj-git-remote-add) +* [`jj git remote list`↴](#jj-git-remote-list) * [`jj git remote remove`↴](#jj-git-remote-remove) * [`jj git remote rename`↴](#jj-git-remote-rename) -* [`jj git remote list`↴](#jj-git-remote-list) -* [`jj git init`↴](#jj-git-init) -* [`jj git fetch`↴](#jj-git-fetch) -* [`jj git clone`↴](#jj-git-clone) -* [`jj git push`↴](#jj-git-push) -* [`jj git import`↴](#jj-git-import) -* [`jj git export`↴](#jj-git-export) * [`jj init`↴](#jj-init) * [`jj interdiff`↴](#jj-interdiff) * [`jj log`↴](#jj-log) @@ -808,76 +808,70 @@ For a comparison with Git, including a table of commands, see https://github.com ###### **Subcommands:** -* `remote` — Manage Git remotes -* `init` — Create a new Git backed repo -* `fetch` — Fetch from a Git remote * `clone` — Create a new repo backed by a clone of a Git repo -* `push` — Push to a Git remote -* `import` — Update repo with changes made in the underlying Git repo * `export` — Update the underlying Git repo with changes made in the repo +* `fetch` — Fetch from a Git remote +* `import` — Update repo with changes made in the underlying Git repo +* `init` — Create a new Git backed repo +* `push` — Push to a Git remote +* `remote` — Manage Git remotes -## `jj git remote` +## `jj git clone` -Manage Git remotes +Create a new repo backed by a clone of a Git repo The Git repo will be a bare git repo stored inside the `.jj/` directory. -**Usage:** `jj git remote ` - -###### **Subcommands:** - -* `add` — Add a Git remote -* `remove` — Remove a Git remote and forget its branches -* `rename` — Rename a Git remote -* `list` — List Git remotes - +**Usage:** `jj git clone [OPTIONS] [DESTINATION]` +###### **Arguments:** -## `jj git remote add` +* `` — URL or path of the Git repo to clone +* `` — The directory to write the Jujutsu repo to -Add a Git remote +###### **Options:** -**Usage:** `jj git remote add ` +* `--colocate` — Whether or not to colocate the Jujutsu repo with the git repo -###### **Arguments:** -* `` — The remote's name -* `` — The remote's URL +## `jj git export` +Update the underlying Git repo with changes made in the repo -## `jj git remote remove` +**Usage:** `jj git export` -Remove a Git remote and forget its branches -**Usage:** `jj git remote remove ` -###### **Arguments:** +## `jj git fetch` -* `` — The remote's name +Fetch from a Git remote +If a working-copy commit gets abandoned, it will be given a new, empty commit. This is true in general; it is not specific to this command. +**Usage:** `jj git fetch [OPTIONS]` -## `jj git remote rename` +###### **Options:** -Rename a Git remote +* `-b`, `--branch ` — Fetch only some of the branches -**Usage:** `jj git remote rename ` + By default, the specified name matches exactly. Use `glob:` prefix to expand `*` as a glob. The other wildcard characters aren't supported. -###### **Arguments:** + Default value: `glob:*` +* `--remote ` — The remote to fetch from (only named remotes are supported, can be repeated) +* `--all-remotes` — Fetch from all remotes -* `` — The name of an existing remote -* `` — The desired name for `old` +## `jj git import` -## `jj git remote list` +Update repo with changes made in the underlying Git repo -List Git remotes +If a working-copy commit gets abandoned, it will be given a new, empty commit. This is true in general; it is not specific to this command. -**Usage:** `jj git remote list` +**Usage:** `jj git import` @@ -910,94 +904,100 @@ Create a new Git backed repo -## `jj git fetch` +## `jj git push` -Fetch from a Git remote +Push to a Git remote -If a working-copy commit gets abandoned, it will be given a new, empty commit. This is true in general; it is not specific to this command. +By default, pushes any branches pointing to `remote_branches(remote=)..@`. Use `--branch` to push specific branches. Use `--all` to push all branches. Use `--change` to generate branch names based on the change IDs of specific commits. -**Usage:** `jj git fetch [OPTIONS]` +Before the command actually moves, creates, or deletes a remote branch, it makes several [safety checks]. If there is a problem, you may need to run `jj git fetch --remote ` and/or resolve some [branch conflicts]. + +[safety checks]: https://martinvonz.github.io/jj/latest/branches/#pushing-branches-safety-checks + +[branch conflicts]: https://martinvonz.github.io/jj/latest/branches/#conflicts + +**Usage:** `jj git push [OPTIONS]` ###### **Options:** -* `-b`, `--branch ` — Fetch only some of the branches +* `--remote ` — The remote to push to (only named remotes are supported) +* `-b`, `--branch ` — Push only this branch, or branches matching a pattern (can be repeated) - By default, the specified name matches exactly. Use `glob:` prefix to expand `*` as a glob. The other wildcard characters aren't supported. + By default, the specified name matches exactly. Use `glob:` prefix to select branches by wildcard pattern. For details, see https://martinvonz.github.io/jj/latest/revsets#string-patterns. +* `--all` — Push all branches (including deleted branches) +* `--tracked` — Push all tracked branches (including deleted branches) - Default value: `glob:*` -* `--remote ` — The remote to fetch from (only named remotes are supported, can be repeated) -* `--all-remotes` — Fetch from all remotes + This usually means that the branch was already pushed to or fetched from the relevant remote. For details, see https://martinvonz.github.io/jj/latest/branches#remotes-and-tracked-branches +* `--deleted` — Push all deleted branches + + Only tracked branches can be successfully deleted on the remote. A warning will be printed if any untracked branches on the remote correspond to missing local branches. +* `--allow-empty-description` — Allow pushing commits with empty descriptions +* `-r`, `--revisions ` — Push branches pointing to these commits (can be repeated) +* `-c`, `--change ` — Push this commit by creating a branch based on its change ID (can be repeated) +* `--dry-run` — Only display what will change on the remote -## `jj git clone` +## `jj git remote` -Create a new repo backed by a clone of a Git repo +Manage Git remotes The Git repo will be a bare git repo stored inside the `.jj/` directory. -**Usage:** `jj git clone [OPTIONS] [DESTINATION]` - -###### **Arguments:** +**Usage:** `jj git remote ` -* `` — URL or path of the Git repo to clone -* `` — The directory to write the Jujutsu repo to +###### **Subcommands:** -###### **Options:** +* `add` — Add a Git remote +* `list` — List Git remotes +* `remove` — Remove a Git remote and forget its branches +* `rename` — Rename a Git remote -* `--colocate` — Whether or not to colocate the Jujutsu repo with the git repo +## `jj git remote add` -## `jj git push` +Add a Git remote -Push to a Git remote +**Usage:** `jj git remote add ` -By default, pushes any branches pointing to `remote_branches(remote=)..@`. Use `--branch` to push specific branches. Use `--all` to push all branches. Use `--change` to generate branch names based on the change IDs of specific commits. +###### **Arguments:** -Before the command actually moves, creates, or deletes a remote branch, it makes several [safety checks]. If there is a problem, you may need to run `jj git fetch --remote ` and/or resolve some [branch conflicts]. +* `` — The remote's name +* `` — The remote's URL -[safety checks]: https://martinvonz.github.io/jj/latest/branches/#pushing-branches-safety-checks -[branch conflicts]: https://martinvonz.github.io/jj/latest/branches/#conflicts -**Usage:** `jj git push [OPTIONS]` +## `jj git remote list` -###### **Options:** +List Git remotes -* `--remote ` — The remote to push to (only named remotes are supported) -* `-b`, `--branch ` — Push only this branch, or branches matching a pattern (can be repeated) +**Usage:** `jj git remote list` - By default, the specified name matches exactly. Use `glob:` prefix to select branches by wildcard pattern. For details, see https://martinvonz.github.io/jj/latest/revsets#string-patterns. -* `--all` — Push all branches (including deleted branches) -* `--tracked` — Push all tracked branches (including deleted branches) - This usually means that the branch was already pushed to or fetched from the relevant remote. For details, see https://martinvonz.github.io/jj/latest/branches#remotes-and-tracked-branches -* `--deleted` — Push all deleted branches - Only tracked branches can be successfully deleted on the remote. A warning will be printed if any untracked branches on the remote correspond to missing local branches. -* `--allow-empty-description` — Allow pushing commits with empty descriptions -* `-r`, `--revisions ` — Push branches pointing to these commits (can be repeated) -* `-c`, `--change ` — Push this commit by creating a branch based on its change ID (can be repeated) -* `--dry-run` — Only display what will change on the remote +## `jj git remote remove` +Remove a Git remote and forget its branches +**Usage:** `jj git remote remove ` -## `jj git import` +###### **Arguments:** -Update repo with changes made in the underlying Git repo +* `` — The remote's name -If a working-copy commit gets abandoned, it will be given a new, empty commit. This is true in general; it is not specific to this command. -**Usage:** `jj git import` +## `jj git remote rename` +Rename a Git remote -## `jj git export` +**Usage:** `jj git remote rename ` -Update the underlying Git repo with changes made in the repo +###### **Arguments:** -**Usage:** `jj git export` +* `` — The name of an existing remote +* `` — The desired name for `old` diff --git a/cli/tests/test_operations.rs b/cli/tests/test_operations.rs index 2d1de0e747..e6a5b160bd 100644 --- a/cli/tests/test_operations.rs +++ b/cli/tests/test_operations.rs @@ -381,7 +381,7 @@ fn test_op_abandon_ancestors() { Abandoned 3 operations and reparented 1 descendant operations. "###); insta::assert_snapshot!( - test_env.jj_cmd_success(&repo_path, &["debug", "workingcopy", "--ignore-working-copy"]), @r###" + test_env.jj_cmd_success(&repo_path, &["debug", "working-copy", "--ignore-working-copy"]), @r###" Current operation: OperationId("10e856d0579c4aca88972ffea0a515f47f8c09dceaa2b1a5d531c83b04350f7aa64a3eff422def01eebd65df26089ef5e0f925f247a8f929c8cc858d16306e53") Current tree: Merge(Resolved(TreeId("4b825dc642cb6eb9a060e54bf8d69288fbee4904"))) "###); @@ -430,7 +430,7 @@ fn test_op_abandon_ancestors() { Abandoned 1 operations and reparented 1 descendant operations. "###); insta::assert_snapshot!( - test_env.jj_cmd_success(&repo_path, &["debug", "workingcopy", "--ignore-working-copy"]), @r###" + test_env.jj_cmd_success(&repo_path, &["debug", "working-copy", "--ignore-working-copy"]), @r###" Current operation: OperationId("445e93662d714f53fb97e450eb3793a8e1a9a4cca1e329d5a9096e65085fb96d5bb51659531145c8abf0db5da803cd11c4cecdcf9025391bc97fc6a42204a0fe") Current tree: Merge(Resolved(TreeId("4b825dc642cb6eb9a060e54bf8d69288fbee4904"))) "###); @@ -475,7 +475,7 @@ fn test_op_abandon_without_updating_working_copy() { Abandoned 1 operations and reparented 1 descendant operations. "###); insta::assert_snapshot!( - test_env.jj_cmd_success(&repo_path, &["debug", "workingcopy", "--ignore-working-copy"]), @r###" + test_env.jj_cmd_success(&repo_path, &["debug", "working-copy", "--ignore-working-copy"]), @r###" Current operation: OperationId("61aeade2493b190412c61b9b0711025c2cccf95966870a5f7dc2e34ab313fbef64da70d00cab2cd69ad39816faeb80a6bc866927549b84dce6cb5a437e0e515b") Current tree: Merge(Resolved(TreeId("4b825dc642cb6eb9a060e54bf8d69288fbee4904"))) "###); @@ -495,7 +495,7 @@ fn test_op_abandon_without_updating_working_copy() { Warning: The working copy operation 61aeade2493b is not updated because it differs from the repo ae6364994418. "###); insta::assert_snapshot!( - test_env.jj_cmd_success(&repo_path, &["debug", "workingcopy", "--ignore-working-copy"]), @r###" + test_env.jj_cmd_success(&repo_path, &["debug", "working-copy", "--ignore-working-copy"]), @r###" Current operation: OperationId("61aeade2493b190412c61b9b0711025c2cccf95966870a5f7dc2e34ab313fbef64da70d00cab2cd69ad39816faeb80a6bc866927549b84dce6cb5a437e0e515b") Current tree: Merge(Resolved(TreeId("4b825dc642cb6eb9a060e54bf8d69288fbee4904"))) "###);