Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
Improve git-remote-rad for use with `jj`
Merged did:key:z6Mkhjou...6fiq opened 10 months ago

This makes jj work a bit better with git-remote-rad:

  • git-remote-rad: Allow pushing from bare repositories

    Bare git repositories are meant to fetch into/push from and fetching works, but pushing from a bare repo into radicle-storage was prohibited.

    This is a problem for me as I want to use jj, which uses a bare git repository in the back (when not co-located into a “normal” git repository).

  • git-remote-rad: Allow pushing commit SHAs into refs/patches

    This makes scripting so much simpler than having to change HEAD or create a branch first.

1 file changed +16 -5 271ef497 a9f75d47
modified crates/radicle-remote-helper/src/push.rs
@@ -390,6 +390,20 @@ pub fn run(
    Ok(())
}

+
fn commit_from_string<'repo>(
+
    working: &'repo git::raw::Repository,
+
    src: &'_ str,
+
) -> Result<git::raw::Commit<'repo>, Error> {
+
    if let Ok(oid) = git::raw::Oid::from_str(src) {
+
        if let Ok(object) = working.find_commit(oid) {
+
            return Ok(object);
+
        }
+
    }
+
    let reference = working.find_reference(src)?;
+
    let commit = reference.peel_to_commit()?;
+
    Ok(commit)
+
}
+

/// Open a new patch.
fn patch_open<G>(
    src: &git::RefStr,
@@ -408,8 +422,7 @@ fn patch_open<G>(
where
    G: crypto::signature::Signer<crypto::Signature>,
{
-
    let reference = working.find_reference(src.as_str())?;
-
    let commit = reference.peel_to_commit()?;
+
    let commit = commit_from_string(working, src.as_str())?;
    let dst = git::refs::storage::staging::patch(nid, commit.id());

    // Before creating the patch, we must push the associated git objects to storage.
@@ -826,9 +839,7 @@ fn push_ref(
    // Nb. The *force* indicator (`+`) is processed by Git tooling before we even reach this code.
    // This happens during the `list for-push` phase.
    let refspec = git::Refspec { src, dst, force };
-
    let repo = working.workdir().ok_or(Error::BareRepository {
-
        path: working.path().to_path_buf(),
-
    })?;
+
    let repo = working.workdir().unwrap_or_else(|| working.path());

    radicle::git::run::<_, _, &str, &str>(
        repo,