diff --git a/cli/src/commands/git/clone.rs b/cli/src/commands/git/clone.rs index 311f62bdcd..4c3e1cc135 100644 --- a/cli/src/commands/git/clone.rs +++ b/cli/src/commands/git/clone.rs @@ -54,6 +54,9 @@ pub struct GitCloneArgs { /// doesn't exist. #[arg(value_hint = clap::ValueHint::DirPath)] destination: Option, + /// Name of the newly created remote + #[arg(long = "remote", default_value = "origin")] + remote_name: String, /// Whether or not to colocate the Jujutsu repo with the git repo #[arg(long)] colocate: bool, @@ -97,10 +100,10 @@ pub fn cmd_git_clone( command: &CommandHelper, args: &GitCloneArgs, ) -> Result<(), CommandError> { + let remote_name = &args.remote_name; if command.global_args().at_operation.is_some() { return Err(cli_error("--at-op is not respected")); } - let remote_name = "origin"; let source = absolute_git_source(command.cwd(), &args.source); let wc_path_str = args .destination diff --git a/cli/tests/test_git_clone.rs b/cli/tests/test_git_clone.rs index 462b18a83a..d8b611fa91 100644 --- a/cli/tests/test_git_clone.rs +++ b/cli/tests/test_git_clone.rs @@ -498,6 +498,30 @@ fn test_git_clone_at_operation() { "###); } +#[test] +fn test_git_clone_with_remote_name() { + let test_env = TestEnvironment::default(); + test_env.add_config("git.auto-local-branch = true"); + let git_repo_path = test_env.env_root().join("source"); + let git_repo = git2::Repository::init(git_repo_path).unwrap(); + set_up_non_empty_git_repo(&git_repo); + + // Clone with relative source path and a non-default remote name + let (stdout, stderr) = test_env.jj_cmd_ok( + test_env.env_root(), + &["git", "clone", "source", "clone", "--remote", "upstream"], + ); + insta::assert_snapshot!(stdout, @""); + insta::assert_snapshot!(stderr, @r#" + Fetching into new repo in "$TEST_ENV/clone" + bookmark: main@upstream [new] tracked + Setting the revset alias "trunk()" to "main@upstream" + Working copy now at: sqpuoqvx cad212e1 (empty) (no description set) + Parent commit : mzyxwzks 9f01a0e0 main | message + Added 1 files, modified 0 files, removed 0 files + "#); +} + fn get_bookmark_output(test_env: &TestEnvironment, repo_path: &Path) -> String { test_env.jj_cmd_success(repo_path, &["bookmark", "list", "--all-remotes"]) } diff --git a/docs/git-comparison.md b/docs/git-comparison.md index eab88a84e7..dc645880d3 100644 --- a/docs/git-comparison.md +++ b/docs/git-comparison.md @@ -105,9 +105,11 @@ parent. Clone an existing repo - jj git clone <source> <destination> (there is no support + jj git clone <source> <destination> + [--remote >remote name<] (there is no support for cloning non-Git repos yet) - git clone <source> <destination> + git clone <source> <destination> + [--origin >remote name<] Update the local repo with all bookmarks from a remote diff --git a/docs/git-compatibility.md b/docs/git-compatibility.md index 60954b801c..87f93ae6da 100644 --- a/docs/git-compatibility.md +++ b/docs/git-compatibility.md @@ -94,6 +94,9 @@ To create a Jujutsu repo from a remote Git URL, use `jj git clone https://github.com/octocat/Hello-World` will clone GitHub's "Hello-World" repo into a directory by the same name. +By default, the remote repository will be named `origin`. You can use +a name of your choice by adding `--remote ` to the `jj +git clone` command. ## Co-located Jujutsu/Git repos