radicle: Allow creating bare clones

This commit is contained in:
Lorenz Leutgeb 2025-09-12 10:41:10 +02:00 committed by Fintan Halpenny
parent e528c40a07
commit 766e281d39
5 changed files with 12 additions and 6 deletions

View File

@ -98,7 +98,7 @@ fn execute(options: Options, profile: &Profile) -> anyhow::Result<PathBuf> {
}
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();

View File

@ -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 ./{}",

View File

@ -562,6 +562,7 @@ fn test_clone() {
alice.signer.public_key(),
tmp.path().join("clone"),
&alice.storage,
false,
)
.unwrap();

View File

@ -251,6 +251,7 @@ pub fn checkout<P: AsRef<Path>, S: storage::ReadStorage>(
remote: &RemoteId,
path: P,
storage: &S,
bare: bool,
) -> Result<git2::Repository, CheckoutError> {
// TODO: Decide on whether we can use `clone_local`
// TODO: Look into sharing object databases.
@ -260,7 +261,8 @@ pub fn checkout<P: AsRef<Path>, 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<P: AsRef<Path>, 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(),

View File

@ -570,6 +570,7 @@ mod tests {
bob.public_key(),
tmp.path().join("working"),
&storage,
false,
)
.unwrap();