From ee9e6de5f347eff1e0472c2aaa30e806c38fe03e Mon Sep 17 00:00:00 2001 From: Lorenz Leutgeb Date: Sat, 13 Sep 2025 11:51:29 +0200 Subject: [PATCH] remote-helper: Do not assume remote name Avoid ending up with an upstream to a potentially non-existent remote when pushing to an anonymous remote. --- crates/radicle-remote-helper/src/main.rs | 3 --- crates/radicle-remote-helper/src/push.rs | 29 +++++++++++++----------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/crates/radicle-remote-helper/src/main.rs b/crates/radicle-remote-helper/src/main.rs index 8bb7adca..b4ae2e49 100644 --- a/crates/radicle-remote-helper/src/main.rs +++ b/crates/radicle-remote-helper/src/main.rs @@ -187,9 +187,6 @@ pub fn run(profile: radicle::Profile) -> Result<(), Error> { } }; - // Assume the default remote if there was no remote. - let remote = remote.unwrap_or_else(|| (*radicle::rad::REMOTE_NAME).clone()); - let stored = profile.storage.repository_mut(url.repo)?; if stored.is_empty()? { return Err(Error::RepositoryNotFound(stored.path().to_path_buf())); diff --git a/crates/radicle-remote-helper/src/push.rs b/crates/radicle-remote-helper/src/push.rs index dd40ddd7..b069a342 100644 --- a/crates/radicle-remote-helper/src/push.rs +++ b/crates/radicle-remote-helper/src/push.rs @@ -246,7 +246,7 @@ impl PushAction { /// Run a git push command. pub fn run( mut specs: Vec, - remote: git::RefString, + remote: Option, url: Url, stored: &storage::git::Repository, profile: &Profile, @@ -477,7 +477,7 @@ pub fn run( /// Open a new patch. fn patch_open( src: &git::Oid, - upstream: &git::RefString, + upstream: &Option, nid: &NodeId, working: &git::raw::Repository, stored: &storage::git::Repository, @@ -564,17 +564,20 @@ where "Create reference for patch head", )?; - // Setup current branch so that pushing updates the patch. - if let Some(branch) = rad::setup_patch_upstream(&patch, head, working, upstream, false)? - { - if let Some(name) = branch.name()? { - if profile.hints() { - // Remove the remote portion of the name, i.e. - // rad/patches/deadbeef -> patches/deadbeef - let name = name.split('/').skip(1).collect::>().join("/"); - hint(format!( - "to update, run `git push` or `git push rad -f HEAD:{name}`" - )); + if let Some(upstream) = upstream { + // Setup current branch so that pushing updates the patch. + if let Some(branch) = + rad::setup_patch_upstream(&patch, head, working, upstream, false)? + { + if let Some(name) = branch.name()? { + if profile.hints() { + // Remove the remote portion of the name, i.e. + // rad/patches/deadbeef -> patches/deadbeef + let name = name.split('/').skip(1).collect::>().join("/"); + hint(format!( + "to update, run `git push` or `git push rad -f HEAD:{name}`" + )); + } } } }