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 13, 2024
1 parent 3df3779 commit 6c47a30
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cli/src/commands/git/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ 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
#[arg(long, default_value_t = 0)]
depth: usize,
}

fn absolute_git_source(cwd: &Path, source: &str) -> String {
Expand Down Expand Up @@ -129,6 +132,7 @@ pub fn cmd_git_clone(
ui,
command,
args.colocate,
args.depth,
remote_name,
&source,
&canonical_wc_path,
Expand Down Expand Up @@ -192,6 +196,7 @@ fn do_git_clone(
ui: &mut Ui,
command: &CommandHelper,
colocate: bool,
depth: usize,
remote_name: &str,
source: &str,
wc_path: &Path,
Expand All @@ -216,6 +221,7 @@ fn do_git_clone(
git::fetch(
fetch_tx.repo_mut(),
&git_repo,
depth,
remote_name,
&[StringPattern::everything()],
cb,
Expand Down
1 change: 1 addition & 0 deletions cli/src/commands/git/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub fn cmd_git_fetch(
git::fetch(
tx.repo_mut(),
&git_repo,
0,
remote,
&args.branch,
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 @@ -958,6 +958,7 @@ The Git repo will be a bare git repo stored inside the `.jj/` directory.
###### **Options:**
* `--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
2 changes: 2 additions & 0 deletions lib/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,7 @@ pub struct GitFetchStats {
pub fn fetch(
mut_repo: &mut MutableRepo,
git_repo: &git2::Repository,
depth: usize,
remote_name: &str,
branch_names: &[StringPattern],
callbacks: RemoteCallbacks<'_>,
Expand All @@ -1260,6 +1261,7 @@ pub fn fetch(
fetch_options.proxy_options(proxy_options);
let callbacks = callbacks.into_git();
fetch_options.remote_callbacks(callbacks);
fetch_options.depth(depth.try_into().unwrap_or(0));
// At this point, we are only updating Git's remote tracking branches, not the
// local branches.
let refspecs: Vec<_> = branch_names
Expand Down
10 changes: 10 additions & 0 deletions lib/tests/test_git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2265,6 +2265,7 @@ fn test_fetch_empty_repo() {
let stats = git::fetch(
tx.repo_mut(),
&test_data.git_repo,
0,
"origin",
&[StringPattern::everything()],
git::RemoteCallbacks::default(),
Expand All @@ -2291,6 +2292,7 @@ fn test_fetch_initial_commit() {
let stats = git::fetch(
tx.repo_mut(),
&test_data.git_repo,
0,
"origin",
&[StringPattern::everything()],
git::RemoteCallbacks::default(),
Expand Down Expand Up @@ -2341,6 +2343,7 @@ fn test_fetch_success() {
git::fetch(
tx.repo_mut(),
&test_data.git_repo,
0,
"origin",
&[StringPattern::everything()],
git::RemoteCallbacks::default(),
Expand All @@ -2364,6 +2367,7 @@ fn test_fetch_success() {
let stats = git::fetch(
tx.repo_mut(),
&test_data.git_repo,
0,
"origin",
&[StringPattern::everything()],
git::RemoteCallbacks::default(),
Expand Down Expand Up @@ -2421,6 +2425,7 @@ fn test_fetch_prune_deleted_ref() {
git::fetch(
tx.repo_mut(),
&test_data.git_repo,
0,
"origin",
&[StringPattern::everything()],
git::RemoteCallbacks::default(),
Expand All @@ -2444,6 +2449,7 @@ fn test_fetch_prune_deleted_ref() {
let stats = git::fetch(
tx.repo_mut(),
&test_data.git_repo,
0,
"origin",
&[StringPattern::everything()],
git::RemoteCallbacks::default(),
Expand Down Expand Up @@ -2471,6 +2477,7 @@ fn test_fetch_no_default_branch() {
git::fetch(
tx.repo_mut(),
&test_data.git_repo,
0,
"origin",
&[StringPattern::everything()],
git::RemoteCallbacks::default(),
Expand All @@ -2494,6 +2501,7 @@ fn test_fetch_no_default_branch() {
let stats = git::fetch(
tx.repo_mut(),
&test_data.git_repo,
0,
"origin",
&[StringPattern::everything()],
git::RemoteCallbacks::default(),
Expand All @@ -2515,6 +2523,7 @@ fn test_fetch_empty_refspecs() {
git::fetch(
tx.repo_mut(),
&test_data.git_repo,
0,
"origin",
&[],
git::RemoteCallbacks::default(),
Expand All @@ -2541,6 +2550,7 @@ fn test_fetch_no_such_remote() {
let result = git::fetch(
tx.repo_mut(),
&test_data.git_repo,
0,
"invalid-remote",
&[StringPattern::everything()],
git::RemoteCallbacks::default(),
Expand Down

0 comments on commit 6c47a30

Please sign in to comment.