Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
remote-helper: Add patch.create-branch option
✗ CI failure Defelo committed 7 months ago
commit 4e6462f0bd92f6e18ccefc760f3ee819842a6a97
parent 7b00bf2e3ac5e83eab262182bf51a5ede656145c
1 failed (1 total) View logs
3 files changed +31 -2
modified crates/radicle-remote-helper/src/main.rs
@@ -167,6 +167,8 @@ pub struct Options {
    base: Option<git::Oid>,
    /// Patch message.
    message: cli::patch::Message,
+
    /// Create a branch when opening a patch.
+
    create_branch: bool,
    verbosity: Verbosity,
}

@@ -289,6 +291,7 @@ fn push_option(args: &[&str], opts: &mut Options) -> Result<(), Error> {
        ["sync.debug"] => opts.sync_debug = true,
        ["no-sync"] => opts.no_sync = true,
        ["patch.draft"] => opts.draft = true,
+
        ["patch.create-branch"] => opts.create_branch = true,
        _ => {
            let args = args.join(" ");

modified crates/radicle-remote-helper/src/push.rs
@@ -564,15 +564,38 @@ where
            )?;

            if let Some(upstream) = upstream {
+
                if opts.create_branch {
+
                    let branch_name = format!("patches/{patch}");
+
                    let local_branch = git::refs::patch(&patch);
+
                    let _ = working.reference(
+
                        &local_branch,
+
                        *head,
+
                        true,
+
                        "Create local branch for patch",
+
                    )?;
+

+
                    let remote_branch = git::refs::workdir::patch_upstream(&patch);
+
                    let remote_branch = working.reference(
+
                        &remote_branch,
+
                        *head,
+
                        true,
+
                        "Create remote tracking branch for patch",
+
                    )?;
+
                    assert!(remote_branch.is_remote());
+

+
                    git::set_upstream(working, upstream, &branch_name, local_branch)?;
+

+
                    hint(format!("to update, run `git push rad {branch_name}`"));
+
                }
                // Setup current branch so that pushing updates the patch.
-
                if let Some(branch) =
+
                else 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::<Vec<_>>().join("/");
+
                            let name = name.split_once('/').unwrap_or_default().1;
                            hint(format!(
                                "to update, run `git push` or `git push rad -f HEAD:{name}`"
                            ));
modified rad-patch.1.adoc
@@ -217,6 +217,9 @@ The full list of options follows:
*patch.draft*::
  Open the patch as a _draft_. Turned off by default.

+
*patch.create-branch*::
+
  Create a branch when opening a patch. Turned off by default.
+

*patch.message*=_<message>_::
  To prevent the editor from opening, you can specify the patch message via this
  option. Multiple *patch.message* options are concatenated with a blank line