cli: Implement `--fetch` on `rad patch`
This commit is contained in:
parent
43bd5fca00
commit
de71c5d9b1
|
|
@ -16,8 +16,9 @@ use std::ffi::OsString;
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
|
|
||||||
use radicle::cob::patch::PatchId;
|
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 as term;
|
||||||
use crate::terminal::args::{Args, Error, Help};
|
use crate::terminal::args::{Args, Error, Help};
|
||||||
use crate::terminal::patch::Message;
|
use crate::terminal::patch::Message;
|
||||||
|
|
@ -82,7 +83,8 @@ pub enum Operation {
|
||||||
pub struct Options {
|
pub struct Options {
|
||||||
pub op: Operation,
|
pub op: Operation,
|
||||||
pub confirm: bool,
|
pub confirm: bool,
|
||||||
pub sync: bool,
|
pub fetch: bool,
|
||||||
|
pub announce: bool,
|
||||||
pub push: bool,
|
pub push: bool,
|
||||||
pub verbose: bool,
|
pub verbose: bool,
|
||||||
}
|
}
|
||||||
|
|
@ -95,7 +97,8 @@ impl Args for Options {
|
||||||
let mut confirm = true;
|
let mut confirm = true;
|
||||||
let mut op: Option<OperationName> = None;
|
let mut op: Option<OperationName> = None;
|
||||||
let mut verbose = false;
|
let mut verbose = false;
|
||||||
let mut sync = true;
|
let mut fetch = false;
|
||||||
|
let mut announce = true;
|
||||||
let mut patch_id = None;
|
let mut patch_id = None;
|
||||||
let mut message = Message::default();
|
let mut message = Message::default();
|
||||||
let mut push = true;
|
let mut push = true;
|
||||||
|
|
@ -119,16 +122,20 @@ impl Args for Options {
|
||||||
Long("no-message") => {
|
Long("no-message") => {
|
||||||
message = Message::Blank;
|
message = Message::Blank;
|
||||||
}
|
}
|
||||||
Long("sync") => {
|
Long("fetch") => {
|
||||||
// By default it is already true, so
|
fetch = true;
|
||||||
// the only case where this is false,
|
|
||||||
// is the case where `no-sync` is specified.
|
|
||||||
}
|
}
|
||||||
Long("no-sync") => {
|
Long("no-fetch") => {
|
||||||
sync = false;
|
fetch = false;
|
||||||
|
}
|
||||||
|
Long("announce") => {
|
||||||
|
announce = true;
|
||||||
|
}
|
||||||
|
Long("no-announce") => {
|
||||||
|
announce = false;
|
||||||
}
|
}
|
||||||
Long("push") => {
|
Long("push") => {
|
||||||
// Skip for the same reason as `sync`.
|
push = true;
|
||||||
}
|
}
|
||||||
Long("no-push") => {
|
Long("no-push") => {
|
||||||
push = false;
|
push = false;
|
||||||
|
|
@ -179,9 +186,10 @@ impl Args for Options {
|
||||||
Options {
|
Options {
|
||||||
op,
|
op,
|
||||||
confirm,
|
confirm,
|
||||||
sync,
|
fetch,
|
||||||
push,
|
push,
|
||||||
verbose,
|
verbose,
|
||||||
|
announce,
|
||||||
},
|
},
|
||||||
vec![],
|
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"))?;
|
.map_err(|_| anyhow!("this command must be run in the context of a project"))?;
|
||||||
|
|
||||||
let profile = ctx.profile()?;
|
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 {
|
match options.op {
|
||||||
Operation::Open { ref message } => {
|
Operation::Open { ref message } => {
|
||||||
create::run(&storage, &profile, &workdir, message.clone(), options)?;
|
create::run(&repository, &profile, &workdir, message.clone(), options)?;
|
||||||
}
|
}
|
||||||
Operation::List => {
|
Operation::List => {
|
||||||
list::run(&storage, &profile, Some(workdir), options)?;
|
list::run(&repository, &profile, Some(workdir))?;
|
||||||
}
|
}
|
||||||
Operation::Show { ref patch_id } => {
|
Operation::Show { ref patch_id } => {
|
||||||
show::run(&storage, &profile, &workdir, patch_id)?;
|
show::run(&repository, &profile, &workdir, patch_id)?;
|
||||||
}
|
}
|
||||||
Operation::Update {
|
Operation::Update {
|
||||||
patch_id,
|
patch_id,
|
||||||
ref message,
|
ref message,
|
||||||
} => {
|
} => {
|
||||||
update::run(
|
update::run(
|
||||||
&storage,
|
&repository,
|
||||||
&profile,
|
&profile,
|
||||||
&workdir,
|
&workdir,
|
||||||
patch_id,
|
patch_id,
|
||||||
|
|
@ -219,7 +231,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
Operation::Checkout { ref patch_id } => {
|
Operation::Checkout { ref patch_id } => {
|
||||||
checkout::run(&storage, &profile, &workdir, patch_id)?;
|
checkout::run(&repository, &profile, &workdir, patch_id)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
|
|
@ -146,7 +146,7 @@ pub fn run(
|
||||||
term::blank();
|
term::blank();
|
||||||
term::success!("Patch {} created 🌱", term::format::highlight(patch.id));
|
term::success!("Patch {} created 🌱", term::format::highlight(patch.id));
|
||||||
|
|
||||||
if options.sync {
|
if options.announce {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,21 +10,15 @@ use unicode_width::UnicodeWidthStr;
|
||||||
use crate::terminal as term;
|
use crate::terminal as term;
|
||||||
|
|
||||||
use super::common;
|
use super::common;
|
||||||
use super::Options;
|
|
||||||
|
|
||||||
/// List patches.
|
/// List patches.
|
||||||
pub fn run(
|
pub fn run(
|
||||||
storage: &Repository,
|
repository: &Repository,
|
||||||
profile: &Profile,
|
profile: &Profile,
|
||||||
workdir: Option<git::raw::Repository>,
|
workdir: Option<git::raw::Repository>,
|
||||||
options: Options,
|
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
if options.sync {
|
|
||||||
// TODO: Sync
|
|
||||||
}
|
|
||||||
|
|
||||||
let me = *profile.id();
|
let me = *profile.id();
|
||||||
let patches = Patches::open(*profile.id(), storage)?;
|
let patches = Patches::open(*profile.id(), repository)?;
|
||||||
let proposed = patches.proposed()?;
|
let proposed = patches.proposed()?;
|
||||||
|
|
||||||
// Patches the user authored.
|
// Patches the user authored.
|
||||||
|
|
@ -49,7 +43,7 @@ pub fn run(
|
||||||
for (id, patch) in &mut own {
|
for (id, patch) in &mut own {
|
||||||
term::blank();
|
term::blank();
|
||||||
|
|
||||||
print(&me, id, patch, &workdir, storage)?;
|
print(&me, id, patch, &workdir, repository)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
term::blank();
|
term::blank();
|
||||||
|
|
@ -62,7 +56,7 @@ pub fn run(
|
||||||
for (id, patch) in &mut other {
|
for (id, patch) in &mut other {
|
||||||
term::blank();
|
term::blank();
|
||||||
|
|
||||||
print(patches.public_key(), id, patch, &workdir, storage)?;
|
print(patches.public_key(), id, patch, &workdir, repository)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
term::blank();
|
term::blank();
|
||||||
|
|
@ -76,9 +70,9 @@ fn print(
|
||||||
patch_id: &PatchId,
|
patch_id: &PatchId,
|
||||||
patch: &Patch,
|
patch: &Patch,
|
||||||
workdir: &Option<git::raw::Repository>,
|
workdir: &Option<git::raw::Repository>,
|
||||||
storage: &Repository,
|
repository: &Repository,
|
||||||
) -> anyhow::Result<()> {
|
) -> 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 you = patch.author().id().as_key() == whoami;
|
||||||
let prefix = "└─ ";
|
let prefix = "└─ ";
|
||||||
|
|
@ -102,14 +96,14 @@ fn print(
|
||||||
term::format::highlight(term::format::cob(patch_id)),
|
term::format::highlight(term::format::cob(patch_id)),
|
||||||
term::format::dim(format!("R{}", patch.version())),
|
term::format::dim(format!("R{}", patch.version())),
|
||||||
common::pretty_commit_version(&revision.oid, workdir)?,
|
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!("{}", author_info.join(" "));
|
||||||
term::info!("{prefix}* patch id {}", term::format::highlight(patch_id));
|
term::info!("{prefix}* patch id {}", term::format::highlight(patch_id));
|
||||||
|
|
||||||
let mut timeline = Vec::new();
|
let mut timeline = Vec::new();
|
||||||
for merge in revision.merges.iter() {
|
for merge in revision.merges.iter() {
|
||||||
let peer = storage.remote(&merge.node)?;
|
let peer = repository.remote(&merge.node)?;
|
||||||
let mut badges = Vec::new();
|
let mut badges = Vec::new();
|
||||||
|
|
||||||
if peer.delegate {
|
if peer.delegate {
|
||||||
|
|
@ -136,7 +130,7 @@ fn print(
|
||||||
Some(Verdict::Reject) => term::format::negative(term::format::dim("✗ rejected")),
|
Some(Verdict::Reject) => term::format::negative(term::format::dim("✗ rejected")),
|
||||||
None => term::format::negative(term::format::dim("⋄ reviewed")),
|
None => term::format::negative(term::format::dim("⋄ reviewed")),
|
||||||
};
|
};
|
||||||
let peer = storage.remote(reviewer)?;
|
let peer = repository.remote(reviewer)?;
|
||||||
let mut badges = Vec::new();
|
let mut badges = Vec::new();
|
||||||
|
|
||||||
if peer.delegate {
|
if peer.delegate {
|
||||||
|
|
|
||||||
|
|
@ -140,7 +140,7 @@ pub fn run(
|
||||||
term::success!("Patch {} updated 🌱", term::format::highlight(patch_id));
|
term::success!("Patch {} updated 🌱", term::format::highlight(patch_id));
|
||||||
term::blank();
|
term::blank();
|
||||||
|
|
||||||
if options.sync {
|
if options.announce {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue