Make some improvements to `rad-checkout`
Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
This commit is contained in:
parent
cb2d83daae
commit
ca1b1f4453
|
|
@ -77,12 +77,15 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn execute(options: Options, profile: &Profile) -> anyhow::Result<PathBuf> {
|
pub fn execute(options: Options, profile: &Profile) -> anyhow::Result<PathBuf> {
|
||||||
|
let id = options.id;
|
||||||
let storage = &profile.storage;
|
let storage = &profile.storage;
|
||||||
let repo = storage.repository(options.id)?;
|
let Doc {
|
||||||
let project = repo
|
payload, delegates, ..
|
||||||
|
} = storage
|
||||||
|
.repository(id)?
|
||||||
.project_of(profile.id())
|
.project_of(profile.id())
|
||||||
.context("project could not be found in local storage")?;
|
.context("project could not be found in local storage")?;
|
||||||
let path = PathBuf::from(project.name.clone());
|
let path = PathBuf::from(payload.name.clone());
|
||||||
|
|
||||||
if path.exists() {
|
if path.exists() {
|
||||||
anyhow::bail!("the local path {:?} already exists", path.as_path());
|
anyhow::bail!("the local path {:?} already exists", path.as_path());
|
||||||
|
|
@ -91,12 +94,12 @@ pub fn execute(options: Options, profile: &Profile) -> anyhow::Result<PathBuf> {
|
||||||
term::headline(&format!(
|
term::headline(&format!(
|
||||||
"Initializing local checkout for 🌱 {} ({})",
|
"Initializing local checkout for 🌱 {} ({})",
|
||||||
term::format::highlight(options.id),
|
term::format::highlight(options.id),
|
||||||
project.name,
|
payload.name,
|
||||||
));
|
));
|
||||||
|
|
||||||
let spinner = term::spinner("Performing checkout...");
|
let spinner = term::spinner("Performing checkout...");
|
||||||
let working = match radicle::rad::checkout(options.id, profile.id(), path.clone(), &storage) {
|
let repo = match radicle::rad::checkout(options.id, profile.id(), path.clone(), &storage) {
|
||||||
Ok(working) => working,
|
Ok(repo) => repo,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
spinner.failed();
|
spinner.failed();
|
||||||
term::blank();
|
term::blank();
|
||||||
|
|
@ -106,31 +109,41 @@ pub fn execute(options: Options, profile: &Profile) -> anyhow::Result<PathBuf> {
|
||||||
};
|
};
|
||||||
spinner.finish();
|
spinner.finish();
|
||||||
|
|
||||||
// Setup a remote and tracking branch for all project delegates except yourself.
|
let remotes = delegates
|
||||||
let setup = project::SetupRemote {
|
.iter()
|
||||||
project: options.id,
|
.map(|d| *d.id)
|
||||||
default_branch: project.default_branch.clone(),
|
.filter(|id| id != profile.id())
|
||||||
repo: &working,
|
.collect::<Vec<_>>();
|
||||||
fetch: true,
|
|
||||||
tracking: true,
|
|
||||||
};
|
|
||||||
for remote_id in repo.remote_ids()? {
|
|
||||||
let remote_id = remote_id?;
|
|
||||||
if &remote_id == profile.id() {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some((remote, branch)) = setup.run(remote_id)? {
|
// Setup tracking for project delegates.
|
||||||
|
setup_tracking(
|
||||||
|
project::SetupRemote {
|
||||||
|
project: id,
|
||||||
|
default_branch: payload.default_branch,
|
||||||
|
repo: &repo,
|
||||||
|
fetch: true,
|
||||||
|
tracking: true,
|
||||||
|
},
|
||||||
|
&remotes,
|
||||||
|
)?;
|
||||||
|
|
||||||
|
Ok(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Setup a remote and tracking branch for each given remote.
|
||||||
|
pub fn setup_tracking(setup: project::SetupRemote, remotes: &[NodeId]) -> anyhow::Result<()> {
|
||||||
|
for remote_id in remotes {
|
||||||
|
if let Some((remote, branch)) = setup.run(*remote_id)? {
|
||||||
let remote = remote.name().unwrap(); // Only valid UTF-8 is used.
|
let remote = remote.name().unwrap(); // Only valid UTF-8 is used.
|
||||||
//
|
//
|
||||||
term::success!("Remote {} set", term::format::highlight(remote));
|
term::success!("Remote {} set", term::format::highlight(remote));
|
||||||
term::success!(
|
term::success!(
|
||||||
"Remote-tracking branch {} created for {}",
|
"Remote-tracking branch {} created for {}",
|
||||||
term::format::highlight(&branch),
|
term::format::highlight(&branch),
|
||||||
term::format::tertiary(term::format::node(&remote_id))
|
term::format::tertiary(term::format::node(remote_id))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(path)
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue