diff --git a/crates/radicle-remote-helper/Cargo.toml b/crates/radicle-remote-helper/Cargo.toml index fe256dbd..050a2266 100644 --- a/crates/radicle-remote-helper/Cargo.toml +++ b/crates/radicle-remote-helper/Cargo.toml @@ -11,7 +11,7 @@ rust-version.workspace = true [[bin]] name = "git-remote-rad" -path = "src/git-remote-rad.rs" +path = "src/main.rs" [dependencies] dunce = { workspace = true } diff --git a/crates/radicle-remote-helper/src/git-remote-rad.rs b/crates/radicle-remote-helper/src/git-remote-rad.rs deleted file mode 100644 index 2fa3b02c..00000000 --- a/crates/radicle-remote-helper/src/git-remote-rad.rs +++ /dev/null @@ -1,42 +0,0 @@ -use std::env; -use std::process; - -use radicle::version::Version; - -pub const VERSION: Version = Version { - name: "git-remote-rad", - commit: env!("GIT_HEAD"), - version: env!("RADICLE_VERSION"), - timestamp: env!("SOURCE_DATE_EPOCH"), -}; - -fn main() { - let mut args = env::args(); - - if let Some(lvl) = radicle::logger::env_level() { - let logger = radicle::logger::StderrLogger::new(lvl); - log::set_boxed_logger(Box::new(logger)) - .expect("no other logger should have been set already"); - log::set_max_level(lvl.to_level_filter()); - } - if args.nth(1).as_deref() == Some("--version") { - if let Err(e) = VERSION.write(std::io::stdout()) { - eprintln!("error: {e}"); - process::exit(1); - }; - process::exit(0); - } - - let profile = match radicle::Profile::load() { - Ok(profile) => profile, - Err(err) => { - eprintln!("error: couldn't load profile: {err}"); - process::exit(1); - } - }; - - if let Err(err) = radicle_remote_helper::run(profile) { - eprintln!("error: {err}"); - process::exit(1); - } -} diff --git a/crates/radicle-remote-helper/src/lib.rs b/crates/radicle-remote-helper/src/main.rs similarity index 88% rename from crates/radicle-remote-helper/src/lib.rs rename to crates/radicle-remote-helper/src/main.rs index 817e25bd..381269eb 100644 --- a/crates/radicle-remote-helper/src/lib.rs +++ b/crates/radicle-remote-helper/src/main.rs @@ -1,13 +1,19 @@ -#![warn(clippy::unwrap_used)] -//! The Radicle Git remote helper. +//! A Git remote helper for interacting with Radicle storage and notifying +//! `radicle-node`. //! -//! Communication with the user is done via `stderr` (`eprintln`). -//! Communication with Git tooling is done via `stdout` (`println`). +//! Refer to for documentation +//! on Git remote helpers. +//! +//! Usage of standard streams: +//! - Standard Error ([`eprintln`]) is used for communicating with the user. +//! - Standard Output ([`println`]) is used for communicating with Git tooling. + mod fetch; mod list; mod push; use std::path::PathBuf; +use std::process; use std::str::FromStr; use std::{env, fmt, io}; @@ -16,11 +22,50 @@ use thiserror::Error; use radicle::prelude::NodeId; use radicle::storage::git::transport::local::{Url, UrlError}; use radicle::storage::{ReadRepository, WriteStorage}; +use radicle::version::Version; use radicle::{cob, profile}; use radicle::{git, storage, Profile}; use radicle_cli::git::Rev; use radicle_cli::terminal as cli; +pub const VERSION: Version = Version { + name: "git-remote-rad", + commit: env!("GIT_HEAD"), + version: env!("RADICLE_VERSION"), + timestamp: env!("SOURCE_DATE_EPOCH"), +}; + +fn main() { + let mut args = env::args(); + + if let Some(lvl) = radicle::logger::env_level() { + let logger = radicle::logger::StderrLogger::new(lvl); + log::set_boxed_logger(Box::new(logger)) + .expect("no other logger should have been set already"); + log::set_max_level(lvl.to_level_filter()); + } + if args.nth(1).as_deref() == Some("--version") { + if let Err(e) = VERSION.write(std::io::stdout()) { + eprintln!("error: {e}"); + process::exit(1); + }; + process::exit(0); + } + + let profile = match radicle::Profile::load() { + Ok(profile) => profile, + Err(err) => { + eprintln!("error: couldn't load profile: {err}"); + process::exit(1); + } + }; + + if let Err(err) = run(profile) { + eprintln!("error: {err}"); + process::exit(1); + } +} + #[derive(Debug, Error)] pub enum Error { /// Failed to parse `base`. diff --git a/crates/radicle-remote-helper/src/push/canonical.rs b/crates/radicle-remote-helper/src/push/canonical.rs index ba0640e5..545dcab7 100644 --- a/crates/radicle-remote-helper/src/push/canonical.rs +++ b/crates/radicle-remote-helper/src/push/canonical.rs @@ -27,7 +27,7 @@ where /// Calculates the quorum of the [`git::canonical::Canonical`] provided. /// - /// In some cases, it ensures that the [`head`] is attempting to converge + /// In some cases, it ensures that the head commit is attempting to converge /// with the set of commits of the other [`Did`]s. /// /// If a quorum is found, then it is also ensured that the new [`head`] is a @@ -40,8 +40,6 @@ where /// copy, and that checks that any two commits are related in the graph. /// /// Ensures that the new head and the canonical commit do not diverge. - /// - /// [`head`]: crate::push::canonical::Canonical::head pub fn quorum(self) -> Result<(git::Qualified<'a>, canonical::Object), QuorumError> { self.canonical .quorum()