Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli: Implement `--fetch` on `rad patch`
Alexis Sellier committed 3 years ago
commit de71c5d9b12d362a72a0dea943c01fe8d21c4b9e
parent 43bd5fca00fe5a711ebc56b23bb8bc9e855f1435
4 files changed +40 -34
modified radicle-cli/src/commands/patch.rs
@@ -16,8 +16,9 @@ use std::ffi::OsString;
use anyhow::anyhow;

use radicle::cob::patch::PatchId;
-
use radicle::prelude::*;
+
use radicle::{prelude::*, Node};

+
use crate::commands::rad_fetch as fetch;
use crate::terminal as term;
use crate::terminal::args::{Args, Error, Help};
use crate::terminal::patch::Message;
@@ -82,7 +83,8 @@ pub enum Operation {
pub struct Options {
    pub op: Operation,
    pub confirm: bool,
-
    pub sync: bool,
+
    pub fetch: bool,
+
    pub announce: bool,
    pub push: bool,
    pub verbose: bool,
}
@@ -95,7 +97,8 @@ impl Args for Options {
        let mut confirm = true;
        let mut op: Option<OperationName> = None;
        let mut verbose = false;
-
        let mut sync = true;
+
        let mut fetch = false;
+
        let mut announce = true;
        let mut patch_id = None;
        let mut message = Message::default();
        let mut push = true;
@@ -119,16 +122,20 @@ impl Args for Options {
                Long("no-message") => {
                    message = Message::Blank;
                }
-
                Long("sync") => {
-
                    // By default it is already true, so
-
                    // the only case where this is false,
-
                    // is the case where `no-sync` is specified.
+
                Long("fetch") => {
+
                    fetch = true;
                }
-
                Long("no-sync") => {
-
                    sync = false;
+
                Long("no-fetch") => {
+
                    fetch = false;
+
                }
+
                Long("announce") => {
+
                    announce = true;
+
                }
+
                Long("no-announce") => {
+
                    announce = false;
                }
                Long("push") => {
-
                    // Skip for the same reason as `sync`.
+
                    push = true;
                }
                Long("no-push") => {
                    push = false;
@@ -179,9 +186,10 @@ impl Args for Options {
            Options {
                op,
                confirm,
-
                sync,
+
                fetch,
                push,
                verbose,
+
                announce,
            },
            vec![],
        ))
@@ -193,24 +201,28 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
        .map_err(|_| anyhow!("this command must be run in the context of a project"))?;

    let profile = ctx.profile()?;
-
    let storage = profile.storage.repository(id)?;
+
    let repository = profile.storage.repository(id)?;
+

+
    if options.fetch {
+
        fetch::fetch(repository.id(), &mut Node::new(profile.socket()))?;
+
    }

    match options.op {
        Operation::Open { ref message } => {
-
            create::run(&storage, &profile, &workdir, message.clone(), options)?;
+
            create::run(&repository, &profile, &workdir, message.clone(), options)?;
        }
        Operation::List => {
-
            list::run(&storage, &profile, Some(workdir), options)?;
+
            list::run(&repository, &profile, Some(workdir))?;
        }
        Operation::Show { ref patch_id } => {
-
            show::run(&storage, &profile, &workdir, patch_id)?;
+
            show::run(&repository, &profile, &workdir, patch_id)?;
        }
        Operation::Update {
            patch_id,
            ref message,
        } => {
            update::run(
-
                &storage,
+
                &repository,
                &profile,
                &workdir,
                patch_id,
@@ -219,7 +231,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
            )?;
        }
        Operation::Checkout { ref patch_id } => {
-
            checkout::run(&storage, &profile, &workdir, patch_id)?;
+
            checkout::run(&repository, &profile, &workdir, patch_id)?;
        }
    }
    Ok(())
modified radicle-cli/src/commands/patch/create.rs
@@ -146,7 +146,7 @@ pub fn run(
    term::blank();
    term::success!("Patch {} created 🌱", term::format::highlight(patch.id));

-
    if options.sync {
+
    if options.announce {
        // TODO
    }

modified radicle-cli/src/commands/patch/list.rs
@@ -10,21 +10,15 @@ use unicode_width::UnicodeWidthStr;
use crate::terminal as term;

use super::common;
-
use super::Options;

/// List patches.
pub fn run(
-
    storage: &Repository,
+
    repository: &Repository,
    profile: &Profile,
    workdir: Option<git::raw::Repository>,
-
    options: Options,
) -> anyhow::Result<()> {
-
    if options.sync {
-
        // TODO: Sync
-
    }
-

    let me = *profile.id();
-
    let patches = Patches::open(*profile.id(), storage)?;
+
    let patches = Patches::open(*profile.id(), repository)?;
    let proposed = patches.proposed()?;

    // Patches the user authored.
@@ -49,7 +43,7 @@ pub fn run(
        for (id, patch) in &mut own {
            term::blank();

-
            print(&me, id, patch, &workdir, storage)?;
+
            print(&me, id, patch, &workdir, repository)?;
        }
    }
    term::blank();
@@ -62,7 +56,7 @@ pub fn run(
        for (id, patch) in &mut other {
            term::blank();

-
            print(patches.public_key(), id, patch, &workdir, storage)?;
+
            print(patches.public_key(), id, patch, &workdir, repository)?;
        }
    }
    term::blank();
@@ -76,9 +70,9 @@ fn print(
    patch_id: &PatchId,
    patch: &Patch,
    workdir: &Option<git::raw::Repository>,
-
    storage: &Repository,
+
    repository: &Repository,
) -> anyhow::Result<()> {
-
    let target_head = common::patch_merge_target_oid(patch.target(), storage)?;
+
    let target_head = common::patch_merge_target_oid(patch.target(), repository)?;

    let you = patch.author().id().as_key() == whoami;
    let prefix = "└─ ";
@@ -102,14 +96,14 @@ fn print(
        term::format::highlight(term::format::cob(patch_id)),
        term::format::dim(format!("R{}", patch.version())),
        common::pretty_commit_version(&revision.oid, workdir)?,
-
        common::pretty_sync_status(storage.raw(), *revision.oid, target_head)?,
+
        common::pretty_sync_status(repository.raw(), *revision.oid, target_head)?,
    );
    term::info!("{}", author_info.join(" "));
    term::info!("{prefix}* patch id {}", term::format::highlight(patch_id));

    let mut timeline = Vec::new();
    for merge in revision.merges.iter() {
-
        let peer = storage.remote(&merge.node)?;
+
        let peer = repository.remote(&merge.node)?;
        let mut badges = Vec::new();

        if peer.delegate {
@@ -136,7 +130,7 @@ fn print(
            Some(Verdict::Reject) => term::format::negative(term::format::dim("✗ rejected")),
            None => term::format::negative(term::format::dim("⋄ reviewed")),
        };
-
        let peer = storage.remote(reviewer)?;
+
        let peer = repository.remote(reviewer)?;
        let mut badges = Vec::new();

        if peer.delegate {
modified radicle-cli/src/commands/patch/update.rs
@@ -140,7 +140,7 @@ pub fn run(
    term::success!("Patch {} updated 🌱", term::format::highlight(patch_id));
    term::blank();

-
    if options.sync {
+
    if options.announce {
        // TODO
    }