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:
parent
664aa570e6
commit
4176d62e38
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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] => {
|
||||||
println!("unsupported");
|
match *opt {
|
||||||
|
"sync" => opts.no_sync = false,
|
||||||
|
"no-sync" => opts.no_sync = true,
|
||||||
|
_ => {
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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,13 +196,15 @@ pub fn run(
|
||||||
stored.sign_refs(&signer)?;
|
stored.sign_refs(&signer)?;
|
||||||
stored.set_head()?;
|
stored.set_head()?;
|
||||||
|
|
||||||
// Connect to local node and announce refs to the network.
|
if !opts.no_sync {
|
||||||
// If our node is not running, we simply skip this step, as the
|
// Connect to local node and announce refs to the network.
|
||||||
// refs will be announced eventually, when the node restarts.
|
// If our node is not running, we simply skip this step, as the
|
||||||
let node = radicle::Node::new(profile.socket());
|
// refs will be announced eventually, when the node restarts.
|
||||||
if node.is_running() {
|
let node = radicle::Node::new(profile.socket());
|
||||||
// Nb. allow this to fail. The push to local storage was still successful.
|
if node.is_running() {
|
||||||
sync(stored.id, node).ok();
|
// Nb. allow this to fail. The push to local storage was still successful.
|
||||||
|
sync(stored.id, node).ok();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue