Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli: Call `rad sync` on `git push rad`
Alexis Sellier committed 3 years ago
commit 7d72b160874af0c029241f7b97df65987b41cd62
parent fed4e84dd7d7b3d1cca268bf53e801409a06a4a1
8 files changed +48 -27
modified radicle-cli-test/src/lib.rs
@@ -221,7 +221,7 @@ impl TestFormula {
                } else {
                    PathBuf::from(&assertion.command)
                };
-
                log::debug!(target: "test", "{path}: Running `{}` in `{}`..", cmd.display(), self.cwd.display());
+
                log::debug!(target: "test", "{path}: Running `{}` with {:?} in `{}`..", cmd.display(), assertion.args, self.cwd.display());

                if !self.cwd.exists() {
                    log::error!(target: "test", "{path}: Directory {} does not exist..", self.cwd.display());
modified radicle-cli/examples/rad-patch.md
@@ -72,6 +72,13 @@ index 0000000..e69de29

```

+
We can also see that it set an upstream for our patch branch:
+
```
+
$ git branch -vv
+
* flux-capacitor-power 3e674d1 [rad/flux-capacitor-power] Define power requirements
+
  master               f2de534 [rad/master] Second commit
+
```
+

Wait, let's add a README too! Just for fun.

```
modified radicle-cli/src/commands/patch.rs
@@ -21,6 +21,7 @@ use anyhow::anyhow;

use radicle::cob::patch;
use radicle::cob::patch::PatchId;
+
use radicle::storage::git::transport;
use radicle::{prelude::*, Node};

use crate::commands::rad_sync as sync;
@@ -258,6 +259,8 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
    let profile = ctx.profile()?;
    let repository = profile.storage.repository(id)?;

+
    transport::local::register(profile.storage.clone());
+

    if options.fetch {
        sync::fetch_all(repository.id(), &mut Node::new(profile.socket()))?;
    }
modified radicle-cli/src/commands/patch/common.rs
@@ -1,6 +1,4 @@
-
use std::path::Path;
-

-
use anyhow::anyhow;
+
use anyhow::{anyhow, Context};

use radicle::cob::patch::{Clock, MergeTarget, Patch, PatchId, Patches};
use radicle::git;
@@ -136,11 +134,15 @@ pub fn try_branch(reference: git::raw::Reference<'_>) -> anyhow::Result<git::raw
///
/// The branch must be in storage for others to merge the `Patch`.
pub fn push_to_storage(
+
    working: &git::raw::Repository,
    storage: &Repository,
    head_branch: &git::raw::Branch,
    options: &Options,
-
) -> anyhow::Result<()> {
+
) -> anyhow::Result<git::RefString> {
    let head_oid = branch_oid(head_branch)?;
+
    let branch = branch_name(head_branch)?.try_into()?;
+
    let branch = radicle::git::refs::workdir::branch(branch);
+

    if storage.commit(head_oid).is_err() {
        if !options.push {
            term::blank();
@@ -152,21 +154,13 @@ pub fn push_to_storage(
            .into());
        }

-
        let output = match head_branch.upstream() {
-
            Ok(_) => git::run::<_, _, &str, &str>(Path::new("."), ["push", "rad"], [])?,
-
            Err(_) => git::run::<_, _, &str, &str>(
-
                Path::new("."),
-
                ["push", "--set-upstream", "rad", branch_name(head_branch)?],
-
                [],
-
            )?,
-
        };
-
        if options.verbose {
-
            term::blob(output);
-

-
            return Ok(());
-
        }
+
        let (mut remote, _) = radicle::rad::remote(working)?;
+

+
        remote
+
            .push::<&str>(&[&branch], None)
+
            .context("failed to push to storage")?;
    }
-
    Ok(())
+
    Ok(branch)
}

/// Find patches with a merge base equal to the one provided.
modified radicle-cli/src/commands/patch/create.rs
@@ -88,9 +88,19 @@ pub fn run(
) -> anyhow::Result<()> {
    let mut patches = patch::Patches::open(storage)?;
    let head_branch = try_branch(workdir.head()?)?;
-
    push_to_storage(storage, &head_branch, &options)?;
+
    let head_branch_name = push_to_storage(workdir, storage, &head_branch, &options)?;
+

    let (target_ref, target_oid) = get_merge_target(storage, &head_branch)?;

+
    if head_branch.upstream().is_err() {
+
        radicle::git::set_upstream(
+
            workdir,
+
            &radicle::rad::REMOTE_NAME,
+
            branch_name(&head_branch)?,
+
            &head_branch_name,
+
        )?;
+
    }
+

    // TODO: Handle case where `rad/master` isn't up to date with the target.
    // In that case we should warn the user that their master branch is not up
    // to date, and error out, unless the user specifies manually the merge
modified radicle-cli/src/commands/patch/update.rs
@@ -71,7 +71,7 @@ pub fn run(
    // `HEAD`; This is what we are proposing as a patch.
    let head_branch = try_branch(workdir.head()?)?;

-
    push_to_storage(storage, &head_branch, options)?;
+
    push_to_storage(workdir, storage, &head_branch, options)?;

    let (_, target_oid) = get_merge_target(storage, &head_branch)?;
    let mut patches = patch::Patches::open(storage)?;
modified radicle-cli/src/terminal.rs
@@ -129,7 +129,7 @@ pub fn fail(header: &str, error: &anyhow::Error) {
    let separator = if err.contains('\n') { ":\n" } else { ": " };

    println!(
-
        "{ERROR_PREFIX} {}{}{error}",
+
        "{ERROR_PREFIX} {}{}{error:#}",
        Paint::red(header).bold(),
        Paint::red(separator),
    );
modified radicle-remote-helper/src/lib.rs
@@ -1,4 +1,5 @@
#![allow(clippy::collapsible_if)]
+
use std::os::fd::{AsRawFd, FromRawFd};
use std::path::PathBuf;
use std::{env, io, process};

@@ -125,11 +126,17 @@ pub fn run(profile: radicle::Profile) -> Result<(), Box<dyn std::error::Error +
                        // 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 mut node = radicle::Node::new(profile.socket());
-
                        if node.is_running() {
-
                            eprint!("Announcing refs... ");
-
                            node.announce_refs(url.repo)?;
-
                            eprintln!("ok");
+
                        if radicle::Node::new(profile.socket()).is_running() {
+
                            let stderr = io::stderr().as_raw_fd();
+

+
                            process::Command::new("rad")
+
                                .arg("sync")
+
                                .arg(proj.id.to_string())
+
                                .arg("--verbose")
+
                                .stdout(unsafe { process::Stdio::from_raw_fd(stderr) })
+
                                .stderr(process::Stdio::inherit())
+
                                .spawn()?
+
                                .wait()?;
                        }
                    }
                }