Harness the power of signify(1) to sign arbitrary git objects
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

impl signature rm command

+88
+27
src/main.rs
··· 4 4 mod push; 5 5 mod raw; 6 6 mod rev_lookup; 7 + mod rm; 7 8 mod shell_completions; 8 9 mod sign; 9 10 mod utils; ··· 29 30 /// Primitive signing and verification commands 30 31 #[command(subcommand)] 31 32 Raw(RawAction), 33 + /// Remove git-signify data 34 + #[command(subcommand)] 35 + Rm(RmAction), 32 36 /// Hash a key and return it 33 37 Fingerprint { 34 38 /// The path to the base64 encoded key to hash ··· 111 115 }, 112 116 } 113 117 118 + #[derive(Subcommand)] 119 + enum RmAction { 120 + /// Remove git-signify signatures 121 + Signature { 122 + /// The path to the base64 encoded public key of the signer 123 + #[arg(short = 'k', long, env = "GIT_KEY_PUB")] 124 + public_key: PathBuf, 125 + 126 + /// The name of the remote repository, in case 127 + /// we wish to remove a remote signature 128 + #[arg(short = 'R', long)] 129 + remote: Option<String>, 130 + 131 + /// The git revision whose signature we wish to remove 132 + git_rev: String, 133 + }, 134 + } 135 + 114 136 fn main() -> Result<()> { 115 137 let args = Args::parse(); 116 138 ··· 124 146 print_signed_oid: recover, 125 147 git_tree: rev, 126 148 }) => raw::verify::command(public_key, recover, rev), 149 + Action::Rm(RmAction::Signature { 150 + public_key, 151 + git_rev, 152 + remote, 153 + }) => rm::signature::command(public_key, git_rev, remote), 127 154 Action::Fingerprint { key } => fingerprint::command(key), 128 155 Action::Sign { 129 156 secret_key,
+3
src/rm.rs
··· 1 + //! Remove git-signify data. 2 + 3 + pub mod signature;
+58
src/rm/signature.rs
··· 1 + //! Remove git-signify signatures. 2 + 3 + use std::fs; 4 + use std::io; 5 + use std::path::PathBuf; 6 + use std::process::Command; 7 + 8 + use anyhow::{anyhow, Context, Result}; 9 + 10 + use crate::utils; 11 + 12 + /// Execute the `rm signature` command. 13 + pub fn command(public_key: PathBuf, rev: String, remote: Option<String>) -> Result<()> { 14 + let repo = utils::open_repository()?; 15 + 16 + for public_key in utils::get_public_keys(public_key)?.into_values() { 17 + let tree_rev = { 18 + let object_oid = repo 19 + .revparse_single(&rev) 20 + .context("Failed to look-up git object")? 21 + .id(); 22 + let key_fingerprint = public_key.fingerprint()?; 23 + utils::craft_signature_reference(key_fingerprint, object_oid) 24 + }; 25 + 26 + if let Some(remote) = remote.as_ref() { 27 + let exit_code = Command::new("git") 28 + .arg("push") 29 + .arg("-d") 30 + .arg(remote) 31 + .arg(tree_rev) 32 + .spawn() 33 + .context("Failed to spawn git command to remove remote signature")? 34 + .wait() 35 + .context("Failed to wait for git command to remove remote signature")?; 36 + if !exit_code.success() { 37 + return Err(anyhow!("Exit code of git: {exit_code}")); 38 + } 39 + } else { 40 + let mut path = PathBuf::new(); 41 + 42 + path.push(".git"); 43 + path.push(tree_rev); 44 + 45 + fs::remove_file(path) 46 + .or_else(|e| { 47 + if e.kind() == io::ErrorKind::NotFound { 48 + Ok(()) 49 + } else { 50 + Err(e) 51 + } 52 + }) 53 + .context("Failed to remove local git reference")?; 54 + } 55 + } 56 + 57 + Ok(()) 58 + }