Skip to content

Commit

Permalink
git clone: Add depth argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Veykril committed Sep 15, 2024
1 parent 783fbc4 commit 7e9bfea
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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.
Expand Down
10 changes: 9 additions & 1 deletion cli/src/commands/git/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<u32>,
}

fn absolute_git_source(cwd: &Path, source: &str) -> String {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -195,6 +202,7 @@ fn do_git_clone(
ui: &mut Ui,
command: &CommandHelper,
colocate: bool,
depth: Option<NonZeroU32>,
remote_name: &str,
source: &str,
wc_path: &Path,
Expand All @@ -219,7 +227,7 @@ fn do_git_clone(
git::fetch(
fetch_tx.repo_mut(),
&git_repo,
None,
depth,
remote_name,
&[StringPattern::everything()],
cb,
Expand Down
1 change: 1 addition & 0 deletions cli/tests/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -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 <DEPTH>` — Create a shallow clone of the given depth
Expand Down

0 comments on commit 7e9bfea

Please sign in to comment.