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 `+`: And that we can with `+`:
``` (stderr) RAD_SOCKET=/dev/null ``` (stderr)
$ git push rad +HEAD:alice/1 $ git push -o no-sync rad +HEAD:alice/1
To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
+ 87fa120...145e1e6 HEAD -> alice/1 (forced update) + 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 $ git branch -r -vv
rad/alice/1 145e1e6 Alice's amended commit rad/alice/1 145e1e6 Alice's amended commit

View File

@ -53,6 +53,12 @@ pub enum Error {
List(#[from] list::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. /// Run the radicle remote helper using the given profile.
pub fn run(profile: radicle::Profile) -> Result<(), Error> { pub fn run(profile: radicle::Profile) -> Result<(), Error> {
let url: Url = { let url: Url = {
@ -80,6 +86,7 @@ pub fn run(profile: radicle::Profile) -> Result<(), Error> {
let stdin = io::stdin(); let stdin = io::stdin();
let mut line = String::new(); let mut line = String::new();
let mut opts = Options::default();
loop { loop {
let tokens = read_line(&stdin, &mut line)?; let tokens = read_line(&stdin, &mut line)?;
@ -94,8 +101,16 @@ pub fn run(profile: radicle::Profile) -> Result<(), Error> {
["option", "verbosity"] => { ["option", "verbosity"] => {
println!("ok"); println!("ok");
} }
["option", "push-option", _opt] => { ["option", "push-option", opt] => {
match *opt {
"sync" => opts.no_sync = false,
"no-sync" => opts.no_sync = true,
_ => {
println!("unsupported"); println!("unsupported");
continue;
}
}
println!("ok");
} }
["option", "progress", ..] => { ["option", "progress", ..] => {
println!("unsupported"); println!("unsupported");
@ -115,6 +130,7 @@ pub fn run(profile: radicle::Profile) -> Result<(), Error> {
&stored, &stored,
&profile, &profile,
&stdin, &stdin,
&opts,
) )
.map_err(Error::from); .map_err(Error::from);
} }

View File

@ -19,7 +19,7 @@ use radicle::Profile;
use radicle::{git, rad}; use radicle::{git, rad};
use radicle_cli::terminal as cli; 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. /// Default timeout for syncing to the network after a push.
const DEFAULT_SYNC_TIMEOUT: time::Duration = time::Duration::from_secs(9); const DEFAULT_SYNC_TIMEOUT: time::Duration = time::Duration::from_secs(9);
@ -117,6 +117,7 @@ pub fn run(
stored: &storage::git::Repository, stored: &storage::git::Repository,
profile: &Profile, profile: &Profile,
stdin: &io::Stdin, stdin: &io::Stdin,
opts: &Options,
) -> Result<(), Error> { ) -> Result<(), Error> {
// Don't allow push if either of these conditions is true: // Don't allow push if either of these conditions is true:
// //
@ -195,6 +196,7 @@ pub fn run(
stored.sign_refs(&signer)?; stored.sign_refs(&signer)?;
stored.set_head()?; stored.set_head()?;
if !opts.no_sync {
// Connect to local node and announce refs to the network. // Connect to local node and announce refs to the network.
// If our node is not running, we simply skip this step, as the // If our node is not running, we simply skip this step, as the
// refs will be announced eventually, when the node restarts. // refs will be announced eventually, when the node restarts.
@ -204,6 +206,7 @@ pub fn run(
sync(stored.id, node).ok(); sync(stored.id, node).ok();
} }
} }
}
// Done. // Done.
println!(); println!();