Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
remote-helper: Support push --force-with-lease
✗ CI failure Defelo committed 5 months ago
commit b7ef1a218aee4391a71a33c517602a64334e2d27
parent 6d0c571ea9998dd98bf10cc191848029f5210d8a
1 passed 4 failed (5 total) View logs
7 files changed +45 -12
modified crates/radicle-cli/examples/git/git-push-amend.md
@@ -20,7 +20,7 @@ $ git commit --amend -m "Neue Änderungen" --allow-empty -q
```

``` ~alice (stderr)
-
$ git push rad master -f
+
$ git push rad master --force-with-lease
✓ Canonical reference refs/heads/master updated to target commit 9170c8795d3a78f0381a0ffafb20ea69fb0f5b6b
✓ Synced with 1 seed(s)
To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
modified crates/radicle-cli/examples/git/git-push-rollback.md
@@ -53,7 +53,7 @@ Since the canonical head is still decidable from this commit she is allowed to
push and the new canonical head becomes the previous commit again:

``` ~alice (stderr)
-
$ git push rad -f
+
$ git push rad --force-with-lease
✓ Canonical reference refs/heads/master updated to target commit f2de534b5e81d7c6e2dcaf58c3dd91573c0a0354
✓ Synced with 1 seed(s)
To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
modified crates/radicle-cli/examples/git/git-tag.md
@@ -63,7 +63,7 @@ Updated tag 'v1.0' (was be18ed6)
```

``` ~alice (stderr)
-
$ git push rad v1.0 -f
+
$ git push rad v1.0 --force-with-lease
✓ Synced with 1 seed(s)
To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
 + be18ed6...9dbdebc v1.0 -> v1.0 (forced update)
modified crates/radicle-cli/examples/rad-patch-revert-merge.md
@@ -49,7 +49,7 @@ HEAD is now at f2de534 Second commit
When pushing, notice that we're told our patch is reverted.

``` (stderr) RAD_SOCKET=/dev/null
-
$ git push rad master --force
+
$ git push rad master --force-with-lease
! Patch 696ec5508494692899337afe6713fe1796d0315c reverted at revision 696ec55
✓ Canonical reference refs/heads/master updated to target commit f2de534b5e81d7c6e2dcaf58c3dd91573c0a0354
To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
modified crates/radicle-cli/examples/rad-patch-via-push.md
@@ -9,7 +9,7 @@ Switched to a new branch 'feature/1'
$ git commit -a -m "Add things" -q --allow-empty
$ git push -o patch.message="Add things #1" -o patch.message="See commits for details." rad HEAD:refs/patches
✓ Patch 6035d2f582afbe01ff23ea87528ae523d76875b6 opened
-
hint: to update, run `git push` or `git push rad -f HEAD:patches/6035d2f582afbe01ff23ea87528ae523d76875b6`
+
hint: to update, run `git push` or `git push rad --force-with-lease HEAD:patches/6035d2f582afbe01ff23ea87528ae523d76875b6`
hint: offline push, your node is not running
hint: to sync with the network, run `rad node start`
To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
@@ -203,10 +203,10 @@ hint: See the 'Note about fast-forwards' in 'git push --help' for details.
```

The push fails because it's not a fast-forward update. To remedy this, we can
-
use `--force` to force the update.
+
use `--force-with-lease` (or `--force`) to force the update.

``` (stderr)
-
$ git push --force
+
$ git push --force-with-lease
✓ Patch 9580891 updated to revision 670d02794aa05afd6e0851f4aa848bc87c4712c7
To compare against your previous revision d7040c6, run:

modified crates/radicle-remote-helper/src/main.rs
@@ -240,6 +240,7 @@ pub fn run(profile: radicle::Profile) -> Result<(), Error> {
    let stdin = io::stdin();
    let mut line = String::new();
    let mut opts = Options::default();
+
    let mut expected_refs = Vec::new();

    if let Err(e) = radicle::io::set_file_limit(4096) {
        if debug {
@@ -278,6 +279,10 @@ pub fn run(profile: radicle::Profile) -> Result<(), Error> {
                push_option(args, &mut opts)?;
                println!("ok");
            }
+
            ["option", "cas", refstr] => {
+
                expected_refs.push((*refstr).to_owned());
+
                println!("ok");
+
            }
            ["option", "progress", ..] | ["option", ..] => {
                println!("unsupported");
            }
@@ -301,6 +306,7 @@ pub fn run(profile: radicle::Profile) -> Result<(), Error> {
                    &profile,
                    &stdin,
                    opts,
+
                    &expected_refs,
                )?);
            }
            ["list"] => {
modified crates/radicle-remote-helper/src/push.rs
@@ -251,6 +251,7 @@ pub fn run(
    profile: &Profile,
    stdin: &io::Stdin,
    opts: Options,
+
    expected_refs: &[String],
) -> Result<(), Error> {
    // Don't allow push if either of these conditions is true:
    //
@@ -341,6 +342,7 @@ pub fn run(
                        patches,
                        &signer,
                        opts.clone(),
+
                        expected_refs,
                    ),
                    PushAction::PushRef { dst } => {
                        let identity = stored.identity()?;
@@ -361,6 +363,7 @@ pub fn run(
                            patches,
                            &signer,
                            opts.verbosity,
+
                            expected_refs,
                        )?;
                        // If we're trying to update the canonical head, make sure
                        // we don't diverge from the current head. This only applies
@@ -512,7 +515,14 @@ impl<'a> TempPatchRef<'a> {
    }

    fn push(&self, src: &git::Oid, verbosity: Verbosity) -> Result<(), Error> {
-
        push_ref(src, &self.reference, false, self.stored.raw(), verbosity)
+
        push_ref(
+
            src,
+
            &self.reference,
+
            false,
+
            self.stored.raw(),
+
            verbosity,
+
            &[],
+
        )
    }
}

@@ -655,7 +665,7 @@ where
                    // rad/patches/deadbeef -> patches/deadbeef
                    let name = name.split_once('/').unwrap_or_default().1;
                    hint(format!(
-
                        "to update, run `git push` or `git push {upstream} -f HEAD:{name}`"
+
                        "to update, run `git push` or `git push {upstream} --force-with-lease HEAD:{name}`"
                    ));
                }
            }
@@ -681,6 +691,7 @@ fn patch_update<G>(
    >,
    signer: &Device<G>,
    opts: Options,
+
    expected_refs: &[String],
) -> Result<Option<ExplorerResource>, Error>
where
    G: crypto::signature::Signer<crypto::Signature>,
@@ -709,7 +720,14 @@ where
        term::patch::get_update_message(opts.message, &stored.backend, &latest, &head.into())?;

    let dst = dst.with_namespace(nid.into());
-
    push_ref(head, &dst, force, stored.raw(), opts.verbosity)?;
+
    push_ref(
+
        head,
+
        &dst,
+
        force,
+
        stored.raw(),
+
        opts.verbosity,
+
        expected_refs,
+
    )?;

    let mut patch_mut = patch::PatchMut::new(patch_id, patch, &mut patches);
    let revision = patch_mut.update(message, base, *head, signer)?;
@@ -758,6 +776,7 @@ fn push<G>(
    >,
    signer: &Device<G>,
    verbosity: Verbosity,
+
    expected_refs: &[String],
) -> Result<Option<ExplorerResource>, Error>
where
    G: crypto::signature::Signer<crypto::Signature>,
@@ -767,7 +786,7 @@ where
    // 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, stored.raw(), verbosity)?;
+
    push_ref(src, &dst, force, stored.raw(), verbosity, expected_refs)?;

    if let Some(old) = old {
        let proj = stored.project()?;
@@ -950,19 +969,27 @@ fn push_ref(
    force: bool,
    stored: &git::raw::Repository,
    verbosity: Verbosity,
+
    expected_refs: &[String],
) -> Result<(), Error> {
    let path = dunce::canonicalize(stored.path())?.display().to_string();
    // 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::fmt::refspec::Refspec { src, dst, force };

-
    let mut args = vec!["send-pack".to_string()];
+
    let mut args = vec!["push".to_string()];

    let verbosity: git::Verbosity = verbosity.into();
    args.extend(verbosity.into_flag());

    args.extend([path.to_string(), refspec.to_string()]);

+
    for expected in expected_refs {
+
        args.push(format!(
+
            "--force-with-lease=refs/namespaces/{}/{expected}",
+
            dst.namespace()
+
        ));
+
    }
+

    // Rely on the environment variable `GIT_DIR`.
    let working = None;