diff --git a/CHANGELOG.md b/CHANGELOG.md index 949069405b..1d7652f6c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,6 +59,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). * Initial support for shallow git repositories has been implemented. However deepening the history of a shallow repository is not yet supported. +* `jj git clone` now accepts a `--depth ` option, which + allows to clone the repository with a given depth. + ### Fixed bugs * Fixed panic when parsing invalid conflict markers of a particular form. diff --git a/cli/src/commands/git/clone.rs b/cli/src/commands/git/clone.rs index 804b5a85d9..f757fd983c 100644 --- a/cli/src/commands/git/clone.rs +++ b/cli/src/commands/git/clone.rs @@ -15,6 +15,7 @@ use std::fs; use std::io; use std::io::Write; +use std::num::NonZeroU32; use std::path::Path; use std::path::PathBuf; @@ -60,6 +61,11 @@ pub struct GitCloneArgs { /// Whether or not to colocate the Jujutsu repo with the git repo #[arg(long)] colocate: bool, + /// Create a shallow clone of the given depth + // We accept a depth of 0 for parity with git's --depth option. + // The option is here to not render a default = 0 in the help message. + #[arg(long)] + depth: Option, } fn absolute_git_source(cwd: &Path, source: &str) -> String { @@ -132,6 +138,7 @@ pub fn cmd_git_clone( ui, command, args.colocate, + args.depth.and_then(NonZeroU32::new), remote_name, &source, &canonical_wc_path, @@ -195,6 +202,7 @@ fn do_git_clone( ui: &mut Ui, command: &CommandHelper, colocate: bool, + depth: Option, remote_name: &str, source: &str, wc_path: &Path, @@ -219,7 +227,7 @@ fn do_git_clone( git::fetch( fetch_tx.repo_mut(), &git_repo, - None, + depth, remote_name, &[StringPattern::everything()], cb, diff --git a/cli/tests/cli-reference@.md.snap b/cli/tests/cli-reference@.md.snap index 8d255d7af6..a6242b4452 100644 --- a/cli/tests/cli-reference@.md.snap +++ b/cli/tests/cli-reference@.md.snap @@ -961,6 +961,7 @@ The Git repo will be a bare git repo stored inside the `.jj/` directory. Default value: `origin` * `--colocate` — Whether or not to colocate the Jujutsu repo with the git repo +* `--depth ` — Create a shallow clone of the given depth