From 766e281d3928fe35da422a685657713cad0ea339 Mon Sep 17 00:00:00 2001 From: Lorenz Leutgeb Date: Fri, 12 Sep 2025 10:41:10 +0200 Subject: [PATCH] radicle: Allow creating bare clones --- crates/radicle-cli/src/commands/checkout.rs | 2 +- crates/radicle-cli/src/commands/clone.rs | 2 +- crates/radicle-node/src/tests/e2e.rs | 1 + crates/radicle/src/rad.rs | 12 ++++++++---- crates/radicle/src/storage/refs.rs | 1 + 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/crates/radicle-cli/src/commands/checkout.rs b/crates/radicle-cli/src/commands/checkout.rs index 1c637479..265a8611 100644 --- a/crates/radicle-cli/src/commands/checkout.rs +++ b/crates/radicle-cli/src/commands/checkout.rs @@ -98,7 +98,7 @@ fn execute(options: Options, profile: &Profile) -> anyhow::Result { } let mut spinner = term::spinner("Performing checkout..."); - let repo = match radicle::rad::checkout(options.id, &remote, path.clone(), &storage) { + let repo = match radicle::rad::checkout(options.id, &remote, path.clone(), &storage, false) { Ok(repo) => repo, Err(err) => { spinner.failed(); diff --git a/crates/radicle-cli/src/commands/clone.rs b/crates/radicle-cli/src/commands/clone.rs index 16ed62f5..142ea0a8 100644 --- a/crates/radicle-cli/src/commands/clone.rs +++ b/crates/radicle-cli/src/commands/clone.rs @@ -274,7 +274,7 @@ impl Checkout { "Creating checkout in ./{}..", term::format::tertiary(destination.display()) )); - match rad::checkout(self.id, &self.remote, self.path, storage) { + match rad::checkout(self.id, &self.remote, self.path, storage, false) { Err(err) => { spinner.message(format!( "Failed to checkout in ./{}", diff --git a/crates/radicle-node/src/tests/e2e.rs b/crates/radicle-node/src/tests/e2e.rs index 1777e85e..ad549d45 100644 --- a/crates/radicle-node/src/tests/e2e.rs +++ b/crates/radicle-node/src/tests/e2e.rs @@ -562,6 +562,7 @@ fn test_clone() { alice.signer.public_key(), tmp.path().join("clone"), &alice.storage, + false, ) .unwrap(); diff --git a/crates/radicle/src/rad.rs b/crates/radicle/src/rad.rs index 21581ecc..969d3c00 100644 --- a/crates/radicle/src/rad.rs +++ b/crates/radicle/src/rad.rs @@ -251,6 +251,7 @@ pub fn checkout, S: storage::ReadStorage>( remote: &RemoteId, path: P, storage: &S, + bare: bool, ) -> Result { // TODO: Decide on whether we can use `clone_local` // TODO: Look into sharing object databases. @@ -260,7 +261,8 @@ pub fn checkout, S: storage::ReadStorage>( let mut opts = git2::RepositoryInitOptions::new(); opts.no_reinit(true) .external_template(false) - .description(project.description()); + .description(project.description()) + .bare(bare); let repo = git2::Repository::init_opts(path.as_ref(), &opts)?; let url = git::Url::from(proj); @@ -318,7 +320,9 @@ pub fn checkout, S: storage::ReadStorage>( .expect("checkout: default branch name is valid UTF-8"); repo.set_head(branch_ref)?; - repo.checkout_head(None)?; + if !bare { + repo.checkout_head(None)?; + } // Setup remote tracking for default branch. git::set_upstream(&repo, &*REMOTE_NAME, project.default_branch(), branch_ref)?; @@ -549,7 +553,7 @@ mod tests { // Bob forks it and creates a checkout. fork(id, &bob, &storage).unwrap(); - checkout(id, bob_id, tempdir.path().join("copy"), &storage).unwrap(); + checkout(id, bob_id, tempdir.path().join("copy"), &storage, false).unwrap(); let bob_remote = storage.repository(id).unwrap().remote(bob_id).unwrap(); @@ -584,7 +588,7 @@ mod tests { .unwrap(); git::set_upstream(&original, "rad", "master", "refs/heads/master").unwrap(); - let copy = checkout(id, remote_id, tempdir.path().join("copy"), &storage).unwrap(); + let copy = checkout(id, remote_id, tempdir.path().join("copy"), &storage, false).unwrap(); assert_eq!( copy.head().unwrap().target(), diff --git a/crates/radicle/src/storage/refs.rs b/crates/radicle/src/storage/refs.rs index 750f8f71..be5b6afa 100644 --- a/crates/radicle/src/storage/refs.rs +++ b/crates/radicle/src/storage/refs.rs @@ -570,6 +570,7 @@ mod tests { bob.public_key(), tmp.path().join("working"), &storage, + false, ) .unwrap();