diff --git a/radicle-cli/examples/git/git-push.md b/radicle-cli/examples/git/git-push.md index 8c27a8db..e27bd2ab 100644 --- a/radicle-cli/examples/git/git-push.md +++ b/radicle-cli/examples/git/git-push.md @@ -28,12 +28,14 @@ hint: See the 'Note about fast-forwards' in 'git push --help' for details. And that we can with `+`: -``` (stderr) RAD_SOCKET=/dev/null -$ git push rad +HEAD:alice/1 +``` (stderr) +$ git push -o no-sync rad +HEAD:alice/1 To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi + 87fa120...145e1e6 HEAD -> alice/1 (forced update) ``` +Notice that we used the `-o no-sync` push option to disable syncing after the push. + ``` $ git branch -r -vv rad/alice/1 145e1e6 Alice's amended commit diff --git a/radicle-remote-helper/src/lib.rs b/radicle-remote-helper/src/lib.rs index 7a6ba885..7452cc98 100644 --- a/radicle-remote-helper/src/lib.rs +++ b/radicle-remote-helper/src/lib.rs @@ -53,6 +53,12 @@ pub enum Error { List(#[from] list::Error), } +#[derive(Debug, Default)] +pub struct Options { + /// Don't sync after push. + no_sync: bool, +} + /// Run the radicle remote helper using the given profile. pub fn run(profile: radicle::Profile) -> Result<(), Error> { let url: Url = { @@ -80,6 +86,7 @@ pub fn run(profile: radicle::Profile) -> Result<(), Error> { let stdin = io::stdin(); let mut line = String::new(); + let mut opts = Options::default(); loop { let tokens = read_line(&stdin, &mut line)?; @@ -94,8 +101,16 @@ pub fn run(profile: radicle::Profile) -> Result<(), Error> { ["option", "verbosity"] => { println!("ok"); } - ["option", "push-option", _opt] => { - println!("unsupported"); + ["option", "push-option", opt] => { + match *opt { + "sync" => opts.no_sync = false, + "no-sync" => opts.no_sync = true, + _ => { + println!("unsupported"); + continue; + } + } + println!("ok"); } ["option", "progress", ..] => { println!("unsupported"); @@ -115,6 +130,7 @@ pub fn run(profile: radicle::Profile) -> Result<(), Error> { &stored, &profile, &stdin, + &opts, ) .map_err(Error::from); } diff --git a/radicle-remote-helper/src/push.rs b/radicle-remote-helper/src/push.rs index 5a5217d4..ea1f6814 100644 --- a/radicle-remote-helper/src/push.rs +++ b/radicle-remote-helper/src/push.rs @@ -19,7 +19,7 @@ use radicle::Profile; use radicle::{git, rad}; use radicle_cli::terminal as cli; -use crate::read_line; +use crate::{read_line, Options}; /// Default timeout for syncing to the network after a push. const DEFAULT_SYNC_TIMEOUT: time::Duration = time::Duration::from_secs(9); @@ -117,6 +117,7 @@ pub fn run( stored: &storage::git::Repository, profile: &Profile, stdin: &io::Stdin, + opts: &Options, ) -> Result<(), Error> { // Don't allow push if either of these conditions is true: // @@ -195,13 +196,15 @@ pub fn run( stored.sign_refs(&signer)?; stored.set_head()?; - // Connect to local node and announce refs to the network. - // If our node is not running, we simply skip this step, as the - // refs will be announced eventually, when the node restarts. - let node = radicle::Node::new(profile.socket()); - if node.is_running() { - // Nb. allow this to fail. The push to local storage was still successful. - sync(stored.id, node).ok(); + if !opts.no_sync { + // Connect to local node and announce refs to the network. + // If our node is not running, we simply skip this step, as the + // refs will be announced eventually, when the node restarts. + let node = radicle::Node::new(profile.socket()); + if node.is_running() { + // Nb. allow this to fail. The push to local storage was still successful. + sync(stored.id, node).ok(); + } } }