Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
remote-helper: Add `no-sync` push option
Alexis Sellier committed 2 years ago
commit 4176d62e38f174c72e24e7f411f2bf9960a2fa42
parent 664aa570e6ec1f948142da1b44032d465c118836
3 files changed +33 -12
modified 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
modified 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);
            }
modified 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();
+
            }
        }
    }