From 761e1d10a4a21818909b3f40fd31504b4cc131da Mon Sep 17 00:00:00 2001 From: Tiago Carvalho Date: Sat, 22 Jul 2023 17:05:08 +0100 Subject: [PATCH] push/pull --- src/main.rs | 14 ++++++++++++++ src/pull.rs | 24 ++++++++++++++++++++++++ src/push.rs | 24 ++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 src/pull.rs create mode 100644 src/push.rs diff --git a/src/main.rs b/src/main.rs index 4d13714..9956a32 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,6 @@ mod fingerprint; +mod pull; +mod push; mod raw; mod sign; mod utils; @@ -47,6 +49,16 @@ enum Action { /// The signed git revision to verify git_rev: String, }, + /// Push signify data to a remote repository + Push { + /// The name of the remote repository + remote: String, + }, + /// Pull signify data from a remote repository + Pull { + /// The name of the remote repository + remote: String, + }, } #[derive(Subcommand)] @@ -97,5 +109,7 @@ fn main() -> Result<()> { public_key, git_rev: rev, } => verify::command(public_key, rev), + Action::Push { remote } => push::command(remote), + Action::Pull { remote } => pull::command(remote), } } diff --git a/src/pull.rs b/src/pull.rs new file mode 100644 index 0000000..3956c16 --- /dev/null +++ b/src/pull.rs @@ -0,0 +1,24 @@ +//! Pull data from a remote repo. + +use std::process::Command; + +use anyhow::{anyhow, Context, Result}; + +use crate::utils::ALL_SIGNIFY_REFS; + +/// Execute the `pull` command. +pub fn command(remote: String) -> Result<()> { + let exit_code = Command::new("git") + .arg("fetch") + .arg(remote) + .arg(format!("{ALL_SIGNIFY_REFS}:{ALL_SIGNIFY_REFS}")) + .spawn() + .context("Failed to spawn git command")? + .wait() + .context("Failed to wait for git command")?; + if exit_code.success() { + Ok(()) + } else { + Err(anyhow!("Exit code of git: {exit_code}")) + } +} diff --git a/src/push.rs b/src/push.rs new file mode 100644 index 0000000..d0cb8d7 --- /dev/null +++ b/src/push.rs @@ -0,0 +1,24 @@ +//! Push data to a remote repo. + +use std::process::Command; + +use anyhow::{anyhow, Context, Result}; + +use crate::utils::ALL_SIGNIFY_REFS; + +/// Execute the `push` command. +pub fn command(remote: String) -> Result<()> { + let exit_code = Command::new("git") + .arg("push") + .arg(remote) + .arg(ALL_SIGNIFY_REFS) + .spawn() + .context("Failed to spawn git command")? + .wait() + .context("Failed to wait for git command")?; + if exit_code.success() { + Ok(()) + } else { + Err(anyhow!("Exit code of git: {exit_code}")) + } +} -- 2.51.2