mirror of
https://seed.radicle.dev/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5.git
synced 2026-11-29 05:50:31 +08:00
cli: Use git push to open or update patches
This adds the ability to the git-remote-helper to open and update patches via a `git push` to the magic ref `refs/patches` and `refs/heads/patches/<patch-id>`. The main change is that we had to move away from offering the `connect` capability in the remote helper, to offering `push` and `fetch` individually. To get a feel for how this works, see the `rad-patch-via-push.md` example.
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
```
|
||||
$ cd heartwood
|
||||
$ git branch -r
|
||||
rad/master
|
||||
z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi/master
|
||||
```
|
||||
|
||||
```
|
||||
$ git ls-remote z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi 'refs/heads/*'
|
||||
145e1e69bef3ad93d14946ea212249c2fa9b9828 refs/heads/alice/1
|
||||
f2de534b5e81d7c6e2dcaf58c3dd91573c0a0354 refs/heads/master
|
||||
```
|
||||
|
||||
``` (stderr)
|
||||
$ git fetch z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
|
||||
From rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
|
||||
* [new branch] alice/1 -> z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi/alice/1
|
||||
```
|
||||
|
||||
```
|
||||
$ git branch -r
|
||||
rad/master
|
||||
z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi/alice/1
|
||||
z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi/master
|
||||
```
|
||||
|
||||
```
|
||||
$ git rev-parse z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi/alice/1
|
||||
145e1e69bef3ad93d14946ea212249c2fa9b9828
|
||||
```
|
||||
@@ -0,0 +1,18 @@
|
||||
Finally, we can also delete branches with `git push`:
|
||||
|
||||
```
|
||||
$ git ls-remote rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi refs/heads/*
|
||||
145e1e69bef3ad93d14946ea212249c2fa9b9828 refs/heads/alice/1
|
||||
f2de534b5e81d7c6e2dcaf58c3dd91573c0a0354 refs/heads/master
|
||||
```
|
||||
|
||||
``` (stderr) RAD_SOCKET=/dev/null
|
||||
$ git push rad :alice/1
|
||||
To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
|
||||
- [deleted] alice/1
|
||||
```
|
||||
|
||||
```
|
||||
$ git ls-remote rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi refs/heads/*
|
||||
f2de534b5e81d7c6e2dcaf58c3dd91573c0a0354 refs/heads/master
|
||||
```
|
||||
@@ -0,0 +1,61 @@
|
||||
```
|
||||
$ git checkout -b alice/1
|
||||
$ git commit -m "Alice's commit" --allow-empty -s
|
||||
[alice/1 87fa120] Alice's commit
|
||||
```
|
||||
|
||||
``` (stderr) RAD_SOCKET=/dev/null
|
||||
$ git push rad HEAD:alice/1
|
||||
To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
|
||||
* [new branch] HEAD -> alice/1
|
||||
```
|
||||
|
||||
Make sure we can't force-push without `+`:
|
||||
|
||||
``` (stderr)
|
||||
$ git commit --amend -m "Alice's amended commit" --allow-empty -s
|
||||
```
|
||||
``` (stderr) (fail)
|
||||
$ git push rad HEAD:alice/1
|
||||
To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
|
||||
! [rejected] HEAD -> alice/1 (non-fast-forward)
|
||||
error: failed to push some refs to 'rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi'
|
||||
hint: Updates were rejected because the tip of your current branch is behind
|
||||
hint: its remote counterpart. Integrate the remote changes (e.g.
|
||||
hint: 'git pull ...') before pushing again.
|
||||
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
|
||||
```
|
||||
|
||||
And that we can with `+`:
|
||||
|
||||
``` (stderr) RAD_SOCKET=/dev/null
|
||||
$ git push rad +HEAD:alice/1
|
||||
To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
|
||||
+ 87fa120...145e1e6 HEAD -> alice/1 (forced update)
|
||||
```
|
||||
|
||||
```
|
||||
$ git branch -r -vv
|
||||
rad/alice/1 145e1e6 Alice's amended commit
|
||||
rad/master f2de534 Second commit
|
||||
```
|
||||
|
||||
List our namespaced refs:
|
||||
|
||||
```
|
||||
$ git ls-remote rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi 'refs/heads/*'
|
||||
145e1e69bef3ad93d14946ea212249c2fa9b9828 refs/heads/alice/1
|
||||
f2de534b5e81d7c6e2dcaf58c3dd91573c0a0354 refs/heads/master
|
||||
```
|
||||
|
||||
List the canonical refs:
|
||||
|
||||
```
|
||||
$ git ls-remote rad
|
||||
f2de534b5e81d7c6e2dcaf58c3dd91573c0a0354 refs/heads/master
|
||||
```
|
||||
|
||||
```
|
||||
$ rad sync
|
||||
✓ Synced with 1 node(s)
|
||||
```
|
||||
@@ -0,0 +1,220 @@
|
||||
# Using `git push` to open patches
|
||||
|
||||
Let's checkout a branch, make a commit and push to the magic ref `refs/patches`.
|
||||
When we push to this ref, a patch is created from our commits.
|
||||
|
||||
``` (stderr)
|
||||
$ git checkout -b feature/1
|
||||
Switched to a new branch 'feature/1'
|
||||
$ git commit -a -m "Add things" -q --allow-empty
|
||||
$ git push rad HEAD:refs/patches
|
||||
To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
|
||||
* [new reference] HEAD -> refs/patches
|
||||
```
|
||||
|
||||
We can see a patch was created:
|
||||
|
||||
```
|
||||
$ rad patch show 8f0e8ec
|
||||
╭─────────────────────────────────────────────────────────────────────────────────────────╮
|
||||
│ Title Add things │
|
||||
│ Patch 8f0e8ecb47a17e8f3219f33150a4092d645e4875 │
|
||||
│ Author did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi │
|
||||
│ Head 42d894a83c9c356552a57af09ccdbd5587a99045 │
|
||||
│ Branches feature/1 │
|
||||
│ Commits ahead 1, behind 0 │
|
||||
│ Status open │
|
||||
├─────────────────────────────────────────────────────────────────────────────────────────┤
|
||||
│ ● opened by did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi (you) [ .. ] │
|
||||
╰─────────────────────────────────────────────────────────────────────────────────────────╯
|
||||
```
|
||||
|
||||
If we check our local branch, we can see its upstream is set to track a remote
|
||||
branch associated with this patch:
|
||||
|
||||
```
|
||||
$ git branch -vv
|
||||
* feature/1 42d894a [rad/patches/8f0e8ecb47a17e8f3219f33150a4092d645e4875] Add things
|
||||
master f2de534 [rad/master] Second commit
|
||||
```
|
||||
|
||||
Let's check that it's up to date with our local head:
|
||||
|
||||
```
|
||||
$ git status --short --branch
|
||||
## feature/1...rad/patches/8f0e8ecb47a17e8f3219f33150a4092d645e4875
|
||||
$ git fetch
|
||||
$ git push
|
||||
```
|
||||
|
||||
And let's look at our local and remote refs:
|
||||
|
||||
```
|
||||
$ git show-ref
|
||||
42d894a83c9c356552a57af09ccdbd5587a99045 refs/heads/feature/1
|
||||
f2de534b5e81d7c6e2dcaf58c3dd91573c0a0354 refs/heads/master
|
||||
f2de534b5e81d7c6e2dcaf58c3dd91573c0a0354 refs/remotes/rad/master
|
||||
42d894a83c9c356552a57af09ccdbd5587a99045 refs/remotes/rad/patches/8f0e8ecb47a17e8f3219f33150a4092d645e4875
|
||||
```
|
||||
```
|
||||
$ git ls-remote rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi 'refs/heads/patches/*'
|
||||
42d894a83c9c356552a57af09ccdbd5587a99045 refs/heads/patches/8f0e8ecb47a17e8f3219f33150a4092d645e4875
|
||||
$ git ls-remote rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi 'refs/cobs/*'
|
||||
8f0e8ecb47a17e8f3219f33150a4092d645e4875 refs/cobs/xyz.radicle.patch/8f0e8ecb47a17e8f3219f33150a4092d645e4875
|
||||
```
|
||||
|
||||
We can also create patches by pushing to the `rad/patches` remote. It's a bit
|
||||
simpler:
|
||||
|
||||
``` (stderr)
|
||||
$ git checkout -b feature/2 -q
|
||||
$ git commit -a -m "Add more things" -q --allow-empty
|
||||
$ git push rad/patches
|
||||
To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
|
||||
* [new reference] HEAD -> refs/patches
|
||||
```
|
||||
|
||||
We see both branches with upstreams now:
|
||||
|
||||
```
|
||||
$ git branch -vv
|
||||
feature/1 42d894a [rad/patches/8f0e8ecb47a17e8f3219f33150a4092d645e4875] Add things
|
||||
* feature/2 b94a835 [rad/patches/8678aafff1d1e28430952abf431e60b87e28023c] Add more things
|
||||
master f2de534 [rad/master] Second commit
|
||||
```
|
||||
|
||||
And both patches:
|
||||
|
||||
```
|
||||
$ rad patch
|
||||
╭────────────────────────────────────────────────────────────────────────────────────╮
|
||||
│ ● ID Title Author Head + - Updated │
|
||||
├────────────────────────────────────────────────────────────────────────────────────┤
|
||||
│ ● 8678aaf Add more things z6MknSL…StBU8Vi (you) b94a835 +0 -0 [ ... ] │
|
||||
│ ● 8f0e8ec Add things z6MknSL…StBU8Vi (you) 42d894a +0 -0 [ ... ] │
|
||||
╰────────────────────────────────────────────────────────────────────────────────────╯
|
||||
```
|
||||
|
||||
Note that we can't fetch from `rad/patches`:
|
||||
|
||||
``` (stderr) (fail)
|
||||
$ git fetch rad/patches
|
||||
fatal: couldn't find remote ref refs/patches
|
||||
```
|
||||
|
||||
To update our patch, we simply push commits to the upstream branch:
|
||||
|
||||
```
|
||||
$ git commit -a -m "Improve code" -q --allow-empty
|
||||
```
|
||||
|
||||
``` (stderr)
|
||||
$ git push
|
||||
4b6618a6ccb0b406659364a70a00bb60e4cd7cf0
|
||||
To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
|
||||
b94a835..662843e feature/2 -> patches/8678aafff1d1e28430952abf431e60b87e28023c
|
||||
```
|
||||
|
||||
This last `git push` worked without specifying an upstream branch despite the
|
||||
local branch having a different name than the remote. This is because Radicle
|
||||
configures repositories upon `rad init` with `push.default = upstream`:
|
||||
|
||||
```
|
||||
$ git config --local --get push.default
|
||||
upstream
|
||||
```
|
||||
|
||||
This allows for pushing to the remote patch branch without using the full
|
||||
`<src>:<dst>` syntax.
|
||||
|
||||
We can then see that the patch head has moved:
|
||||
|
||||
```
|
||||
$ rad patch show 8678aaf
|
||||
╭─────────────────────────────────────────────────────────────────────────────────────────╮
|
||||
│ Title Add more things │
|
||||
│ Patch 8678aafff1d1e28430952abf431e60b87e28023c │
|
||||
│ Author did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi │
|
||||
│ Head 662843ed81e76efa69d7901fb7bdd775043015d0 │
|
||||
│ Branches feature/2 │
|
||||
│ Commits ahead 3, behind 0 │
|
||||
│ Status open │
|
||||
├─────────────────────────────────────────────────────────────────────────────────────────┤
|
||||
│ ● opened by did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi (you) [ ... ] │
|
||||
│ ↑ updated to 4b6618a6ccb0b406659364a70a00bb60e4cd7cf0 (662843e) [ ... ] │
|
||||
╰─────────────────────────────────────────────────────────────────────────────────────────╯
|
||||
```
|
||||
|
||||
And we can check that all the refs are properly updated in our repository:
|
||||
|
||||
```
|
||||
$ git rev-parse HEAD
|
||||
662843ed81e76efa69d7901fb7bdd775043015d0
|
||||
```
|
||||
|
||||
```
|
||||
$ git status --short --branch
|
||||
## feature/2...rad/patches/8678aafff1d1e28430952abf431e60b87e28023c
|
||||
```
|
||||
|
||||
```
|
||||
$ git rev-parse refs/remotes/rad/patches/8678aafff1d1e28430952abf431e60b87e28023c
|
||||
662843ed81e76efa69d7901fb7bdd775043015d0
|
||||
$ git ls-remote rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi refs/heads/patches/8678aafff1d1e28430952abf431e60b87e28023c
|
||||
662843ed81e76efa69d7901fb7bdd775043015d0 refs/heads/patches/8678aafff1d1e28430952abf431e60b87e28023c
|
||||
```
|
||||
|
||||
## Force push
|
||||
|
||||
Sometimes, it's necessary to force-push a patch update. For example, if we amended
|
||||
the commit and want the updated patch to reflect that.
|
||||
|
||||
Let's try.
|
||||
|
||||
```
|
||||
$ git commit --amend -m "Amended commit" --allow-empty
|
||||
[feature/2 3507cd5] Amended commit
|
||||
Date: [..]
|
||||
```
|
||||
|
||||
Now let's push to the patch head.
|
||||
|
||||
``` (stderr) (fail)
|
||||
$ git push
|
||||
To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
|
||||
! [rejected] feature/2 -> patches/8678aafff1d1e28430952abf431e60b87e28023c (non-fast-forward)
|
||||
error: failed to push some refs to 'rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi'
|
||||
hint: Updates were rejected because a pushed branch tip is behind its remote
|
||||
hint: counterpart. Check out this branch and integrate the remote changes
|
||||
hint: (e.g. 'git pull ...') before pushing again.
|
||||
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.
|
||||
|
||||
``` (stderr)
|
||||
$ git push --force
|
||||
983f2d21c9fbe91c21ddfbcd3e3d6cd13db0a944
|
||||
To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
|
||||
+ 662843e...3507cd5 feature/2 -> patches/8678aafff1d1e28430952abf431e60b87e28023c (forced update)
|
||||
```
|
||||
|
||||
That worked. We can see the new revision if we call `rad patch show`:
|
||||
|
||||
```
|
||||
$ rad patch show 8678aaf
|
||||
╭─────────────────────────────────────────────────────────────────────────────────────────╮
|
||||
│ Title Add more things │
|
||||
│ Patch 8678aafff1d1e28430952abf431e60b87e28023c │
|
||||
│ Author did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi │
|
||||
│ Head 3507cd57811fe5f21f6a0a610a1ac8068b3a5d9f │
|
||||
│ Branches feature/2 │
|
||||
│ Commits ahead 3, behind 0 │
|
||||
│ Status open │
|
||||
├─────────────────────────────────────────────────────────────────────────────────────────┤
|
||||
│ ● opened by did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi (you) 4 months ago │
|
||||
│ ↑ updated to 4b6618a6ccb0b406659364a70a00bb60e4cd7cf0 (662843e) 4 months ago │
|
||||
│ ↑ updated to 983f2d21c9fbe91c21ddfbcd3e3d6cd13db0a944 (3507cd5) 4 months ago │
|
||||
╰─────────────────────────────────────────────────────────────────────────────────────────╯
|
||||
```
|
||||
@@ -9,9 +9,10 @@ Now, we can see that there is a new remote in the list of remotes:
|
||||
|
||||
```
|
||||
$ rad remote list
|
||||
bob z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk (fetch)
|
||||
rad the canonical upstream (fetch)
|
||||
rad z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi (push)
|
||||
bob z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk (fetch)
|
||||
rad (canonical upstream) (fetch)
|
||||
rad z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi (push)
|
||||
rad/patches (patches upstream) (push)
|
||||
```
|
||||
|
||||
You can see both `bob` and `rad` as remotes. The `rad` remote is our personal remote of the project.
|
||||
|
||||
@@ -62,6 +62,13 @@ $ rad patch show 5f0a547f7a91bf002bb0542035a647fd5af134a5
|
||||
╰─────────────────────────────────────────────────────────────────────────────────────────╯
|
||||
```
|
||||
|
||||
We can also confirm that the patch branch is in storage:
|
||||
|
||||
```
|
||||
$ git ls-remote rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk refs/heads/flux-capacitor-power
|
||||
3e674d1a1df90807e934f9ae5da2591dd6848a33 refs/heads/flux-capacitor-power
|
||||
```
|
||||
|
||||
Wait, let's add a README too! Just for fun.
|
||||
|
||||
```
|
||||
|
||||
@@ -16,7 +16,13 @@ peer. Upcoming versions of radicle will not require this step.
|
||||
```
|
||||
$ rad remote add z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk --name bob
|
||||
✓ Remote bob added with rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk
|
||||
```
|
||||
|
||||
``` (stderr)
|
||||
$ git fetch bob
|
||||
From rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk
|
||||
* [new branch] flux-capacitor-power -> bob/flux-capacitor-power
|
||||
* [new branch] master -> bob/master
|
||||
```
|
||||
|
||||
The contributor's changes are now visible to us.
|
||||
|
||||
Reference in New Issue
Block a user