Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
git-remote: Add tip on how to create a patch
Archived did:key:z6MkkfM3...sVz5 opened 2 years ago

To help users that don’t know how to create a patch in Radicle.
We should show some hint when pushing a new branch.

1 file changed +22 -6 9767b485 65956014
modified radicle-remote-helper/src/push.rs
@@ -266,7 +266,16 @@ pub fn run(
                                return Err(Error::HeadsDiverge(head.into(), *canonical_oid));
                            }
                        }
-
                        push(src, &dst, *force, &nid, &working, stored, &signer)
+
                        push(
+
                            src,
+
                            &dst,
+
                            *force,
+
                            &nid,
+
                            &working,
+
                            stored,
+
                            profile.hints(),
+
                            &signer,
+
                        )
                    }
                }
            }
@@ -504,20 +513,21 @@ fn push<G: Signer>(
    nid: &NodeId,
    working: &git::raw::Repository,
    stored: &storage::git::Repository,
+
    hints: bool,
    signer: &G,
) -> Result<Option<ExplorerResource>, Error> {
-
    let head = working.find_reference(src.as_str())?;
-
    let head = head.peel_to_commit()?.id();
+
    let reference = working.find_reference(src.as_str())?;
+
    let head = reference.peel_to_commit()?.id();
    let dst = dst.with_namespace(nid.into());
    // It's ok for the destination reference to be unknown, eg. when pushing a new branch.
    let old = stored.backend.find_reference(dst.as_str()).ok();

    push_ref(src, &dst, force, working, stored.raw())?;

-
    if let Some(old) = old {
-
        let proj = stored.project()?;
-
        let master = &*git::Qualified::from(git::lit::refs_heads(proj.default_branch()));
+
    let proj = stored.project()?;
+
    let master = &*git::Qualified::from(git::lit::refs_heads(proj.default_branch()));

+
    if let Some(old) = old {
        // If we're pushing to the project's default branch, we want to see if any patches got
        // merged, and if so, update the patch COB.
        if &*dst.strip_namespace() == master {
@@ -527,6 +537,12 @@ fn push<G: Signer>(
                patch_merge_all(old.into(), head.into(), working, stored, signer)?;
            }
        }
+
    } else if let Some(ref_name) = reference.shorthand() {
+
        if hints && &*dst.strip_namespace() != master {
+
            eprintln!("{}", ref_name);
+
            hint(format!("you don't need to push a branch to create a patch, just run git push rad {}:refs/patches.", ref_name));
+
            eprintln!();
+
        }
    }
    Ok(Some(ExplorerResource::Tree { oid: head.into() }))
}