diff --git a/CHANGELOG.md b/CHANGELOG.md index d09fc5fb..b14d148f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,9 +15,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `rad clone` now supports the flag `--bare` which works analoguously to `git clone --bare`. +- `rad init --setup-signing` now works on bare repositories. ## Fixed Bugs +- `rad init --setup-signing` now works in combination with `--existing`. + ## 1.4.0 ## Release Highlights diff --git a/crates/radicle-cli/examples/rad-init-existing-bare.md b/crates/radicle-cli/examples/rad-init-existing-bare.md index cfbefd4f..ba2107ab 100644 --- a/crates/radicle-cli/examples/rad-init-existing-bare.md +++ b/crates/radicle-cli/examples/rad-init-existing-bare.md @@ -20,10 +20,18 @@ rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji And initialize this working copy as that existing repository: ``` -$ rad init --existing rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji +$ rad init --setup-signing --existing rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji + +Configuring radicle signing key SHA256:UIedaL6Cxm6OUErh9GQUzzglSk7VpQlVTI1TAFB/HWA... + +✓ Signing configured in [..]/heartwood/config +! Not writing .gitsigners file. ✓ Initialized existing repository rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji in [..]/heartwood/.. ``` +The warning about not writing `.gitsigners` is expected, as this requires a +working directory, which a bare repository does not have. + We can confirm that the working copy is initialized: ``` $ rad . diff --git a/crates/radicle-cli/examples/rad-init-existing.md b/crates/radicle-cli/examples/rad-init-existing.md index a9bf5879..aa326c1f 100644 --- a/crates/radicle-cli/examples/rad-init-existing.md +++ b/crates/radicle-cli/examples/rad-init-existing.md @@ -20,7 +20,12 @@ rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji And initialize this working copy as that existing repository: ``` -$ rad init --existing rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji +$ rad init --setup-signing --existing rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji + +Configuring radicle signing key SHA256:UIedaL6Cxm6OUErh9GQUzzglSk7VpQlVTI1TAFB/HWA... + +✓ Signing configured in [..]/heartwood/.git/config +✓ Created .gitsigners file ✓ Initialized existing repository rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji in [..]/heartwood/.. ``` diff --git a/crates/radicle-cli/src/commands/init.rs b/crates/radicle-cli/src/commands/init.rs index 967f61b4..a68ea8da 100644 --- a/crates/radicle-cli/src/commands/init.rs +++ b/crates/radicle-cli/src/commands/init.rs @@ -403,6 +403,11 @@ pub fn init_existing( )?; } + if options.setup_signing { + // Setup radicle signing key. + self::setup_signing(profile.id(), &working, options.interactive)?; + } + term::success!( "Initialized existing repository {} in {}..", term::format::tertiary(rid), @@ -633,11 +638,13 @@ pub fn setup_signing( repo: &git::Repository, interactive: Interactive, ) -> anyhow::Result<()> { - let repo = repo - .workdir() - .ok_or(anyhow!("cannot setup signing in bare repository"))?; + const SIGNERS: &str = ".gitsigners"; + + let path = repo.path(); + let config = path.join("config"); + let key = ssh::fmt::fingerprint(node_id); - let yes = if !git::is_signing_configured(repo)? { + let yes = if !git::is_signing_configured(path)? { term::headline(format!( "Configuring radicle signing key {}...", term::format::tertiary(key) @@ -645,14 +652,25 @@ pub fn setup_signing( true } else if interactive.yes() { term::confirm(format!( - "Configure radicle signing key {} in local checkout?", + "Configure radicle signing key {} in {}?", term::format::tertiary(key), + term::format::tertiary(config.display()), )) } else { true }; - if yes { + if !yes { + return Ok(()); + } + + git::configure_signing(path, node_id)?; + term::success!( + "Signing configured in {}", + term::format::tertiary(config.display()) + ); + + if let Some(repo) = repo.workdir() { match git::write_gitsigners(repo, [node_id]) { Ok(file) => { git::ignore(repo, file.as_path())?; @@ -661,11 +679,11 @@ pub fn setup_signing( } Err(err) if err.kind() == std::io::ErrorKind::AlreadyExists => { let ssh_key = ssh::fmt::key(node_id); - let gitsigners = term::format::tertiary(".gitsigners"); + let gitsigners = term::format::tertiary(SIGNERS); term::success!("Found existing {} file", gitsigners); let ssh_keys = - git::read_gitsigners(repo).context("error reading .gitsigners file")?; + git::read_gitsigners(repo).context(format!("error reading {SIGNERS} file"))?; if ssh_keys.contains(&ssh_key) { term::success!("Signing key is already in {gitsigners} file"); @@ -677,13 +695,10 @@ pub fn setup_signing( return Err(err.into()); } } - git::configure_signing(repo, node_id)?; - - term::success!( - "Signing configured in {}", - term::format::tertiary(".git/config") - ); + } else { + term::notice!("Not writing {SIGNERS} file.") } + Ok(()) }