This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
rad-patch-via-push.md
240 lines (199 loc) ยท 11.9 KB
/
rad-patch-via-push.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# 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) RAD_HINT=1
$ git checkout -b feature/1
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: offline push, your node is not running
hint: to sync with the network, run `rad node start`
To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
* [new reference] HEAD -> refs/patches
```
We can see a patch was created:
```
$ rad patch show 6035d2f582afbe01ff23ea87528ae523d76875b6
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ Title Add things #1 โ
โ Patch 6035d2f582afbe01ff23ea87528ae523d76875b6 โ
โ Author z6MknSLโฆStBU8Vi (you) โ
โ Head 42d894a83c9c356552a57af09ccdbd5587a99045 โ
โ Branches feature/1 โ
โ Commits ahead 1, behind 0 โ
โ Status open โ
โ โ
โ See commits for details. โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ 42d894a Add things โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ opened by z6MknSLโฆStBU8Vi (you) (42d894a) now โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
```
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/6035d2f582afbe01ff23ea87528ae523d76875b6] 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/6035d2f582afbe01ff23ea87528ae523d76875b6
$ 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/6035d2f582afbe01ff23ea87528ae523d76875b6
```
```
$ git ls-remote rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji 'refs/heads/patches/*'
42d894a83c9c356552a57af09ccdbd5587a99045 refs/heads/patches/6035d2f582afbe01ff23ea87528ae523d76875b6
$ git ls-remote rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi 'refs/cobs/*'
0656c217f917c3e06234771e9ecae53aba5e173e refs/cobs/xyz.radicle.id/0656c217f917c3e06234771e9ecae53aba5e173e
6035d2f582afbe01ff23ea87528ae523d76875b6 refs/cobs/xyz.radicle.patch/6035d2f582afbe01ff23ea87528ae523d76875b6
```
We can create another patch:
``` (stderr)
$ git checkout -b feature/2 -q master
$ git commit -a -m "Add more things" -q --allow-empty
$ git push rad HEAD:refs/patches
โ Patch 95808913573cead52ad7b42c7b475260ec45c4b2 opened
To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
* [new reference] HEAD -> refs/patches
```
We see both branches with upstreams now:
```
$ git branch -vv
feature/1 42d894a [rad/patches/6035d2f582afbe01ff23ea87528ae523d76875b6] Add things
* feature/2 8b0ea80 [rad/patches/95808913573cead52ad7b42c7b475260ec45c4b2] Add more things
master f2de534 [rad/master] Second commit
```
And both patches:
```
$ rad patch
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ โ ID Title Author Reviews Head + - Updated โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ 6035d2f Add things #1 z6MknSLโฆStBU8Vi (you) - 42d894a +0 -0 now โ
โ โ 9580891 Add more things z6MknSLโฆStBU8Vi (you) - 8b0ea80 +0 -0 now โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
```
To update our patch, we simply push commits to the upstream branch:
```
$ git commit -a -m "Improve code" -q --allow-empty
```
``` (stderr)
$ git push rad
โ Patch 9580891 updated to revision d7040c6c97629c2b94f86fb639bebbff5de39697
To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
8b0ea80..02bef3f feature/2 -> patches/95808913573cead52ad7b42c7b475260ec45c4b2
```
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 9580891
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ Title Add more things โ
โ Patch 95808913573cead52ad7b42c7b475260ec45c4b2 โ
โ Author z6MknSLโฆStBU8Vi (you) โ
โ Head 02bef3fac41b2f98bb3c02b868a53ddfecb55b5f โ
โ Branches feature/2 โ
โ Commits ahead 2, behind 0 โ
โ Status open โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ 02bef3f Improve code โ
โ 8b0ea80 Add more things โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ opened by z6MknSLโฆStBU8Vi (you) (8b0ea80) now โ
โ โ updated to d7040c6c97629c2b94f86fb639bebbff5de39697 (02bef3f) now โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
```
And we can check that all the refs are properly updated in our repository:
```
$ git rev-parse HEAD
02bef3fac41b2f98bb3c02b868a53ddfecb55b5f
```
```
$ git status --short --branch
## feature/2...rad/patches/95808913573cead52ad7b42c7b475260ec45c4b2
```
```
$ git rev-parse refs/remotes/rad/patches/95808913573cead52ad7b42c7b475260ec45c4b2
02bef3fac41b2f98bb3c02b868a53ddfecb55b5f
$ git ls-remote rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi refs/heads/patches/95808913573cead52ad7b42c7b475260ec45c4b2
02bef3fac41b2f98bb3c02b868a53ddfecb55b5f refs/heads/patches/95808913573cead52ad7b42c7b475260ec45c4b2
```
## 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 9304dbc] Amended commit
Date: [..]
```
Now let's push to the patch head.
``` (stderr) (fail)
$ git push
To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
! [rejected] feature/2 -> patches/95808913573cead52ad7b42c7b475260ec45c4b2 (non-fast-forward)
error: failed to push some refs to 'rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi'
hint: [..]
hint: [..]
hint: [..]
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
โ Patch 9580891 updated to revision 670d02794aa05afd6e0851f4aa848bc87c4712c7
To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
+ 02bef3f...9304dbc feature/2 -> patches/95808913573cead52ad7b42c7b475260ec45c4b2 (forced update)
```
That worked. We can see the new revision if we call `rad patch show`:
```
$ rad patch show 9580891
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ Title Add more things โ
โ Patch 95808913573cead52ad7b42c7b475260ec45c4b2 โ
โ Author z6MknSLโฆStBU8Vi (you) โ
โ Head 9304dbc445925187994a7a93222a3f8bde73b785 โ
โ Branches feature/2 โ
โ Commits ahead 2, behind 0 โ
โ Status open โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ 9304dbc Amended commit โ
โ 8b0ea80 Add more things โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ opened by z6MknSLโฆStBU8Vi (you) (8b0ea80) now โ
โ โ updated to d7040c6c97629c2b94f86fb639bebbff5de39697 (02bef3f) now โ
โ โ updated to 670d02794aa05afd6e0851f4aa848bc87c4712c7 (9304dbc) now โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
```
## Empty patch
If we try to open a patch without making any changes to our base branch (`master`),
we should get an error:
``` (stderr) (fail)
$ git push rad master:refs/patches
To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
! [remote rejected] master -> refs/patches (patch commits are already included in the base branch)
error: failed to push some refs to 'rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi'
```