remote-helper: Add `no-sync` push option

This is mainly useful for scripting, when for eg. you want to push
multiple things and sync only once, at the end.
This commit is contained in:
Alexis Sellier 2023-05-24 10:32:32 +02:00
parent 664aa570e6
commit 4176d62e38
No known key found for this signature in database
3 changed files with 33 additions and 12 deletions

View File

@ -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

View File

@ -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);
}

View File

@ -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();
}
}
}