Show More
@@ -1,138 +1,138 b'' | |||
|
1 | 1 | # rewriteutil.py - utility functions for rewriting changesets |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2017 Octobus <contact@octobus.net> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2 or any later version. |
|
7 | 7 | |
|
8 | 8 | from __future__ import absolute_import |
|
9 | 9 | |
|
10 | 10 | import re |
|
11 | 11 | |
|
12 | 12 | from .i18n import _ |
|
13 | 13 | from .node import ( |
|
14 | 14 | hex, |
|
15 | 15 | nullrev, |
|
16 | 16 | ) |
|
17 | 17 | |
|
18 | 18 | from . import ( |
|
19 | 19 | error, |
|
20 | 20 | obsolete, |
|
21 | 21 | obsutil, |
|
22 | 22 | revset, |
|
23 | 23 | scmutil, |
|
24 | 24 | ) |
|
25 | 25 | |
|
26 | 26 | |
|
27 | 27 | NODE_RE = re.compile(br'\b[0-9a-f]{6,64}\b') |
|
28 | 28 | |
|
29 | 29 | |
|
30 | 30 | def precheck(repo, revs, action=b'rewrite'): |
|
31 | 31 | """check if revs can be rewritten |
|
32 | 32 | action is used to control the error message. |
|
33 | 33 | |
|
34 | 34 | Make sure this function is called after taking the lock. |
|
35 | 35 | """ |
|
36 | 36 | if nullrev in revs: |
|
37 |
msg = _(b"cannot %s null |
|
|
37 | msg = _(b"cannot %s the null revision") % action | |
|
38 | 38 | hint = _(b"no changeset checked out") |
|
39 | 39 | raise error.InputError(msg, hint=hint) |
|
40 | 40 | |
|
41 | 41 | if len(repo[None].parents()) > 1: |
|
42 | 42 | raise error.StateError(_(b"cannot %s while merging") % action) |
|
43 | 43 | |
|
44 | 44 | publicrevs = repo.revs(b'%ld and public()', revs) |
|
45 | 45 | if publicrevs: |
|
46 | 46 | msg = _(b"cannot %s public changesets") % action |
|
47 | 47 | hint = _(b"see 'hg help phases' for details") |
|
48 | 48 | raise error.InputError(msg, hint=hint) |
|
49 | 49 | |
|
50 | 50 | newunstable = disallowednewunstable(repo, revs) |
|
51 | 51 | if newunstable: |
|
52 | 52 | raise error.InputError(_(b"cannot %s changeset with children") % action) |
|
53 | 53 | |
|
54 | 54 | |
|
55 | 55 | def disallowednewunstable(repo, revs): |
|
56 | 56 | """Checks whether editing the revs will create new unstable changesets and |
|
57 | 57 | are we allowed to create them. |
|
58 | 58 | |
|
59 | 59 | To allow new unstable changesets, set the config: |
|
60 | 60 | `experimental.evolution.allowunstable=True` |
|
61 | 61 | """ |
|
62 | 62 | allowunstable = obsolete.isenabled(repo, obsolete.allowunstableopt) |
|
63 | 63 | if allowunstable: |
|
64 | 64 | return revset.baseset() |
|
65 | 65 | return repo.revs(b"(%ld::) - %ld", revs, revs) |
|
66 | 66 | |
|
67 | 67 | |
|
68 | 68 | def skip_empty_successor(ui, command): |
|
69 | 69 | empty_successor = ui.config(b'rewrite', b'empty-successor') |
|
70 | 70 | if empty_successor == b'skip': |
|
71 | 71 | return True |
|
72 | 72 | elif empty_successor == b'keep': |
|
73 | 73 | return False |
|
74 | 74 | else: |
|
75 | 75 | raise error.ConfigError( |
|
76 | 76 | _( |
|
77 | 77 | b"%s doesn't know how to handle config " |
|
78 | 78 | b"rewrite.empty-successor=%s (only 'skip' and 'keep' are " |
|
79 | 79 | b"supported)" |
|
80 | 80 | ) |
|
81 | 81 | % (command, empty_successor) |
|
82 | 82 | ) |
|
83 | 83 | |
|
84 | 84 | |
|
85 | 85 | def update_hash_refs(repo, commitmsg, pending=None): |
|
86 | 86 | """Replace all obsolete commit hashes in the message with the current hash. |
|
87 | 87 | |
|
88 | 88 | If the obsolete commit was split or is divergent, the hash is not replaced |
|
89 | 89 | as there's no way to know which successor to choose. |
|
90 | 90 | |
|
91 | 91 | For commands that update a series of commits in the current transaction, the |
|
92 | 92 | new obsolete markers can be considered by setting ``pending`` to a mapping |
|
93 | 93 | of ``pending[oldnode] = [successor_node1, successor_node2,..]``. |
|
94 | 94 | """ |
|
95 | 95 | if not pending: |
|
96 | 96 | pending = {} |
|
97 | 97 | cache = {} |
|
98 | 98 | hashes = re.findall(NODE_RE, commitmsg) |
|
99 | 99 | unfi = repo.unfiltered() |
|
100 | 100 | for h in hashes: |
|
101 | 101 | fullnode = scmutil.resolvehexnodeidprefix(unfi, h) |
|
102 | 102 | if fullnode is None: |
|
103 | 103 | continue |
|
104 | 104 | ctx = unfi[fullnode] |
|
105 | 105 | if not ctx.obsolete(): |
|
106 | 106 | successors = pending.get(fullnode) |
|
107 | 107 | if successors is None: |
|
108 | 108 | continue |
|
109 | 109 | # obsutil.successorssets() returns a list of list of nodes |
|
110 | 110 | successors = [successors] |
|
111 | 111 | else: |
|
112 | 112 | successors = obsutil.successorssets(repo, ctx.node(), cache=cache) |
|
113 | 113 | |
|
114 | 114 | # We can't make any assumptions about how to update the hash if the |
|
115 | 115 | # cset in question was split or diverged. |
|
116 | 116 | if len(successors) == 1 and len(successors[0]) == 1: |
|
117 | 117 | successor = successors[0][0] |
|
118 | 118 | if successor is not None: |
|
119 | 119 | newhash = hex(successor) |
|
120 | 120 | commitmsg = commitmsg.replace(h, newhash[: len(h)]) |
|
121 | 121 | else: |
|
122 | 122 | repo.ui.note( |
|
123 | 123 | _( |
|
124 | 124 | b'The stale commit message reference to %s could ' |
|
125 | 125 | b'not be updated\n(The referenced commit was dropped)\n' |
|
126 | 126 | ) |
|
127 | 127 | % h |
|
128 | 128 | ) |
|
129 | 129 | else: |
|
130 | 130 | repo.ui.note( |
|
131 | 131 | _( |
|
132 | 132 | b'The stale commit message reference to %s could ' |
|
133 | 133 | b'not be updated\n' |
|
134 | 134 | ) |
|
135 | 135 | % h |
|
136 | 136 | ) |
|
137 | 137 | |
|
138 | 138 | return commitmsg |
@@ -1,596 +1,596 b'' | |||
|
1 | 1 | Test uncommit - set up the config |
|
2 | 2 | |
|
3 | 3 | $ cat >> $HGRCPATH <<EOF |
|
4 | 4 | > [experimental] |
|
5 | 5 | > evolution.createmarkers=True |
|
6 | 6 | > evolution.allowunstable=True |
|
7 | 7 | > [extensions] |
|
8 | 8 | > uncommit = |
|
9 | 9 | > drawdag=$TESTDIR/drawdag.py |
|
10 | 10 | > EOF |
|
11 | 11 | |
|
12 | 12 | Build up a repo |
|
13 | 13 | |
|
14 | 14 | $ hg init repo |
|
15 | 15 | $ cd repo |
|
16 | 16 | $ hg bookmark foo |
|
17 | 17 | |
|
18 | 18 | Help for uncommit |
|
19 | 19 | |
|
20 | 20 | $ hg help uncommit |
|
21 | 21 | hg uncommit [OPTION]... [FILE]... |
|
22 | 22 | |
|
23 | 23 | uncommit part or all of a local changeset |
|
24 | 24 | |
|
25 | 25 | This command undoes the effect of a local commit, returning the affected |
|
26 | 26 | files to their uncommitted state. This means that files modified or |
|
27 | 27 | deleted in the changeset will be left unchanged, and so will remain |
|
28 | 28 | modified in the working directory. |
|
29 | 29 | |
|
30 | 30 | If no files are specified, the commit will be pruned, unless --keep is |
|
31 | 31 | given. |
|
32 | 32 | |
|
33 | 33 | (use 'hg help -e uncommit' to show help for the uncommit extension) |
|
34 | 34 | |
|
35 | 35 | options ([+] can be repeated): |
|
36 | 36 | |
|
37 | 37 | --keep allow an empty commit after uncommitting |
|
38 | 38 | --allow-dirty-working-copy allow uncommit with outstanding changes |
|
39 | 39 | -n --note TEXT store a note on uncommit |
|
40 | 40 | -I --include PATTERN [+] include names matching the given patterns |
|
41 | 41 | -X --exclude PATTERN [+] exclude names matching the given patterns |
|
42 | 42 | -m --message TEXT use text as commit message |
|
43 | 43 | -l --logfile FILE read commit message from file |
|
44 | 44 | -d --date DATE record the specified date as commit date |
|
45 | 45 | -u --user USER record the specified user as committer |
|
46 | 46 | -D --currentdate record the current date as commit date |
|
47 | 47 | -U --currentuser record the current user as committer |
|
48 | 48 | |
|
49 | 49 | (some details hidden, use --verbose to show complete help) |
|
50 | 50 | |
|
51 | 51 | Uncommit with no commits should fail |
|
52 | 52 | |
|
53 | 53 | $ hg uncommit |
|
54 |
abort: cannot uncommit null |
|
|
54 | abort: cannot uncommit the null revision | |
|
55 | 55 | (no changeset checked out) |
|
56 | 56 | [10] |
|
57 | 57 | |
|
58 | 58 | Create some commits |
|
59 | 59 | |
|
60 | 60 | $ touch files |
|
61 | 61 | $ hg add files |
|
62 | 62 | $ for i in a ab abc abcd abcde; do echo $i > files; echo $i > file-$i; hg add file-$i; hg commit -m "added file-$i"; done |
|
63 | 63 | $ ls -A |
|
64 | 64 | .hg |
|
65 | 65 | file-a |
|
66 | 66 | file-ab |
|
67 | 67 | file-abc |
|
68 | 68 | file-abcd |
|
69 | 69 | file-abcde |
|
70 | 70 | files |
|
71 | 71 | |
|
72 | 72 | $ hg log -G -T '{rev}:{node} {desc}' --hidden |
|
73 | 73 | @ 4:6c4fd43ed714e7fcd8adbaa7b16c953c2e985b60 added file-abcde |
|
74 | 74 | | |
|
75 | 75 | o 3:6db330d65db434145c0b59d291853e9a84719b24 added file-abcd |
|
76 | 76 | | |
|
77 | 77 | o 2:abf2df566fc193b3ac34d946e63c1583e4d4732b added file-abc |
|
78 | 78 | | |
|
79 | 79 | o 1:69a232e754b08d568c4899475faf2eb44b857802 added file-ab |
|
80 | 80 | | |
|
81 | 81 | o 0:3004d2d9b50883c1538fc754a3aeb55f1b4084f6 added file-a |
|
82 | 82 | |
|
83 | 83 | Simple uncommit off the top, also moves bookmark |
|
84 | 84 | |
|
85 | 85 | $ hg bookmark |
|
86 | 86 | * foo 4:6c4fd43ed714 |
|
87 | 87 | $ hg uncommit |
|
88 | 88 | $ hg status |
|
89 | 89 | M files |
|
90 | 90 | A file-abcde |
|
91 | 91 | $ hg bookmark |
|
92 | 92 | * foo 3:6db330d65db4 |
|
93 | 93 | |
|
94 | 94 | $ hg log -G -T '{rev}:{node} {desc}' --hidden |
|
95 | 95 | x 4:6c4fd43ed714e7fcd8adbaa7b16c953c2e985b60 added file-abcde |
|
96 | 96 | | |
|
97 | 97 | @ 3:6db330d65db434145c0b59d291853e9a84719b24 added file-abcd |
|
98 | 98 | | |
|
99 | 99 | o 2:abf2df566fc193b3ac34d946e63c1583e4d4732b added file-abc |
|
100 | 100 | | |
|
101 | 101 | o 1:69a232e754b08d568c4899475faf2eb44b857802 added file-ab |
|
102 | 102 | | |
|
103 | 103 | o 0:3004d2d9b50883c1538fc754a3aeb55f1b4084f6 added file-a |
|
104 | 104 | |
|
105 | 105 | |
|
106 | 106 | Recommit |
|
107 | 107 | |
|
108 | 108 | $ hg commit -m 'new change abcde' |
|
109 | 109 | $ hg status |
|
110 | 110 | $ hg heads -T '{rev}:{node} {desc}' |
|
111 | 111 | 5:0c07a3ccda771b25f1cb1edbd02e683723344ef1 new change abcde (no-eol) |
|
112 | 112 | |
|
113 | 113 | Uncommit of non-existent and unchanged files aborts |
|
114 | 114 | $ hg uncommit nothinghere |
|
115 | 115 | abort: cannot uncommit "nothinghere" |
|
116 | 116 | (file does not exist) |
|
117 | 117 | [10] |
|
118 | 118 | $ hg status |
|
119 | 119 | $ hg uncommit file-abc |
|
120 | 120 | abort: cannot uncommit "file-abc" |
|
121 | 121 | (file was not changed in working directory parent) |
|
122 | 122 | [10] |
|
123 | 123 | $ hg status |
|
124 | 124 | |
|
125 | 125 | Try partial uncommit, also moves bookmark |
|
126 | 126 | |
|
127 | 127 | $ hg bookmark |
|
128 | 128 | * foo 5:0c07a3ccda77 |
|
129 | 129 | $ hg uncommit files |
|
130 | 130 | $ hg status |
|
131 | 131 | M files |
|
132 | 132 | $ hg bookmark |
|
133 | 133 | * foo 6:3727deee06f7 |
|
134 | 134 | $ hg heads -T '{rev}:{node} {desc}' |
|
135 | 135 | 6:3727deee06f72f5ffa8db792ee299cf39e3e190b new change abcde (no-eol) |
|
136 | 136 | $ hg log -r . -p -T '{rev}:{node} {desc}' |
|
137 | 137 | 6:3727deee06f72f5ffa8db792ee299cf39e3e190b new change abcdediff -r 6db330d65db4 -r 3727deee06f7 file-abcde |
|
138 | 138 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
139 | 139 | +++ b/file-abcde Thu Jan 01 00:00:00 1970 +0000 |
|
140 | 140 | @@ -0,0 +1,1 @@ |
|
141 | 141 | +abcde |
|
142 | 142 | |
|
143 | 143 | $ hg log -G -T '{rev}:{node} {desc}' --hidden |
|
144 | 144 | @ 6:3727deee06f72f5ffa8db792ee299cf39e3e190b new change abcde |
|
145 | 145 | | |
|
146 | 146 | | x 5:0c07a3ccda771b25f1cb1edbd02e683723344ef1 new change abcde |
|
147 | 147 | |/ |
|
148 | 148 | | x 4:6c4fd43ed714e7fcd8adbaa7b16c953c2e985b60 added file-abcde |
|
149 | 149 | |/ |
|
150 | 150 | o 3:6db330d65db434145c0b59d291853e9a84719b24 added file-abcd |
|
151 | 151 | | |
|
152 | 152 | o 2:abf2df566fc193b3ac34d946e63c1583e4d4732b added file-abc |
|
153 | 153 | | |
|
154 | 154 | o 1:69a232e754b08d568c4899475faf2eb44b857802 added file-ab |
|
155 | 155 | | |
|
156 | 156 | o 0:3004d2d9b50883c1538fc754a3aeb55f1b4084f6 added file-a |
|
157 | 157 | |
|
158 | 158 | $ hg commit -m 'update files for abcde' |
|
159 | 159 | |
|
160 | 160 | Uncommit with dirty state |
|
161 | 161 | |
|
162 | 162 | $ echo "foo" >> files |
|
163 | 163 | $ cat files |
|
164 | 164 | abcde |
|
165 | 165 | foo |
|
166 | 166 | $ hg status |
|
167 | 167 | M files |
|
168 | 168 | $ hg uncommit |
|
169 | 169 | abort: uncommitted changes |
|
170 | 170 | (requires --allow-dirty-working-copy to uncommit) |
|
171 | 171 | [20] |
|
172 | 172 | $ hg uncommit files |
|
173 | 173 | abort: uncommitted changes |
|
174 | 174 | (requires --allow-dirty-working-copy to uncommit) |
|
175 | 175 | [20] |
|
176 | 176 | $ cat files |
|
177 | 177 | abcde |
|
178 | 178 | foo |
|
179 | 179 | $ hg commit --amend -m "files abcde + foo" |
|
180 | 180 | |
|
181 | 181 | Testing the 'experimental.uncommitondirtywdir' config |
|
182 | 182 | |
|
183 | 183 | $ echo "bar" >> files |
|
184 | 184 | $ hg uncommit |
|
185 | 185 | abort: uncommitted changes |
|
186 | 186 | (requires --allow-dirty-working-copy to uncommit) |
|
187 | 187 | [20] |
|
188 | 188 | $ hg uncommit --config experimental.uncommitondirtywdir=True |
|
189 | 189 | $ hg commit -m "files abcde + foo" |
|
190 | 190 | |
|
191 | 191 | Uncommit in the middle of a stack, does not move bookmark |
|
192 | 192 | |
|
193 | 193 | $ hg checkout '.^^^' |
|
194 | 194 | 1 files updated, 0 files merged, 2 files removed, 0 files unresolved |
|
195 | 195 | (leaving bookmark foo) |
|
196 | 196 | $ hg log -r . -p -T '{rev}:{node} {desc}' |
|
197 | 197 | 2:abf2df566fc193b3ac34d946e63c1583e4d4732b added file-abcdiff -r 69a232e754b0 -r abf2df566fc1 file-abc |
|
198 | 198 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
199 | 199 | +++ b/file-abc Thu Jan 01 00:00:00 1970 +0000 |
|
200 | 200 | @@ -0,0 +1,1 @@ |
|
201 | 201 | +abc |
|
202 | 202 | diff -r 69a232e754b0 -r abf2df566fc1 files |
|
203 | 203 | --- a/files Thu Jan 01 00:00:00 1970 +0000 |
|
204 | 204 | +++ b/files Thu Jan 01 00:00:00 1970 +0000 |
|
205 | 205 | @@ -1,1 +1,1 @@ |
|
206 | 206 | -ab |
|
207 | 207 | +abc |
|
208 | 208 | |
|
209 | 209 | $ hg bookmark |
|
210 | 210 | foo 9:48e5bd7cd583 |
|
211 | 211 | $ hg uncommit |
|
212 | 212 | 3 new orphan changesets |
|
213 | 213 | $ hg status |
|
214 | 214 | M files |
|
215 | 215 | A file-abc |
|
216 | 216 | $ hg heads -T '{rev}:{node} {desc}' |
|
217 | 217 | 9:48e5bd7cd583eb24164ef8b89185819c84c96ed7 files abcde + foo (no-eol) |
|
218 | 218 | $ hg bookmark |
|
219 | 219 | foo 9:48e5bd7cd583 |
|
220 | 220 | $ hg commit -m 'new abc' |
|
221 | 221 | created new head |
|
222 | 222 | |
|
223 | 223 | Partial uncommit in the middle, does not move bookmark |
|
224 | 224 | |
|
225 | 225 | $ hg checkout '.^' |
|
226 | 226 | 1 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
227 | 227 | $ hg log -r . -p -T '{rev}:{node} {desc}' |
|
228 | 228 | 1:69a232e754b08d568c4899475faf2eb44b857802 added file-abdiff -r 3004d2d9b508 -r 69a232e754b0 file-ab |
|
229 | 229 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
230 | 230 | +++ b/file-ab Thu Jan 01 00:00:00 1970 +0000 |
|
231 | 231 | @@ -0,0 +1,1 @@ |
|
232 | 232 | +ab |
|
233 | 233 | diff -r 3004d2d9b508 -r 69a232e754b0 files |
|
234 | 234 | --- a/files Thu Jan 01 00:00:00 1970 +0000 |
|
235 | 235 | +++ b/files Thu Jan 01 00:00:00 1970 +0000 |
|
236 | 236 | @@ -1,1 +1,1 @@ |
|
237 | 237 | -a |
|
238 | 238 | +ab |
|
239 | 239 | |
|
240 | 240 | $ hg bookmark |
|
241 | 241 | foo 9:48e5bd7cd583 |
|
242 | 242 | $ hg uncommit file-ab |
|
243 | 243 | 1 new orphan changesets |
|
244 | 244 | $ hg status |
|
245 | 245 | A file-ab |
|
246 | 246 | |
|
247 | 247 | $ hg heads -T '{rev}:{node} {desc}\n' |
|
248 | 248 | 11:8eb87968f2edb7f27f27fe676316e179de65fff6 added file-ab |
|
249 | 249 | 10:5dc89ca4486f8a88716c5797fa9f498d13d7c2e1 new abc |
|
250 | 250 | 9:48e5bd7cd583eb24164ef8b89185819c84c96ed7 files abcde + foo |
|
251 | 251 | |
|
252 | 252 | $ hg bookmark |
|
253 | 253 | foo 9:48e5bd7cd583 |
|
254 | 254 | $ hg commit -m 'update ab' |
|
255 | 255 | $ hg status |
|
256 | 256 | $ hg heads -T '{rev}:{node} {desc}\n' |
|
257 | 257 | 12:f21039c59242b085491bb58f591afc4ed1c04c09 update ab |
|
258 | 258 | 10:5dc89ca4486f8a88716c5797fa9f498d13d7c2e1 new abc |
|
259 | 259 | 9:48e5bd7cd583eb24164ef8b89185819c84c96ed7 files abcde + foo |
|
260 | 260 | |
|
261 | 261 | $ hg log -G -T '{rev}:{node} {desc}' --hidden |
|
262 | 262 | @ 12:f21039c59242b085491bb58f591afc4ed1c04c09 update ab |
|
263 | 263 | | |
|
264 | 264 | o 11:8eb87968f2edb7f27f27fe676316e179de65fff6 added file-ab |
|
265 | 265 | | |
|
266 | 266 | | * 10:5dc89ca4486f8a88716c5797fa9f498d13d7c2e1 new abc |
|
267 | 267 | | | |
|
268 | 268 | | | * 9:48e5bd7cd583eb24164ef8b89185819c84c96ed7 files abcde + foo |
|
269 | 269 | | | | |
|
270 | 270 | | | | x 8:84beeba0ac30e19521c036e4d2dd3a5fa02586ff files abcde + foo |
|
271 | 271 | | | |/ |
|
272 | 272 | | | | x 7:0977fa602c2fd7d8427ed4e7ee15ea13b84c9173 update files for abcde |
|
273 | 273 | | | |/ |
|
274 | 274 | | | * 6:3727deee06f72f5ffa8db792ee299cf39e3e190b new change abcde |
|
275 | 275 | | | | |
|
276 | 276 | | | | x 5:0c07a3ccda771b25f1cb1edbd02e683723344ef1 new change abcde |
|
277 | 277 | | | |/ |
|
278 | 278 | | | | x 4:6c4fd43ed714e7fcd8adbaa7b16c953c2e985b60 added file-abcde |
|
279 | 279 | | | |/ |
|
280 | 280 | | | * 3:6db330d65db434145c0b59d291853e9a84719b24 added file-abcd |
|
281 | 281 | | | | |
|
282 | 282 | | | x 2:abf2df566fc193b3ac34d946e63c1583e4d4732b added file-abc |
|
283 | 283 | | |/ |
|
284 | 284 | | x 1:69a232e754b08d568c4899475faf2eb44b857802 added file-ab |
|
285 | 285 | |/ |
|
286 | 286 | o 0:3004d2d9b50883c1538fc754a3aeb55f1b4084f6 added file-a |
|
287 | 287 | |
|
288 | 288 | Uncommit with draft parent |
|
289 | 289 | |
|
290 | 290 | $ hg uncommit |
|
291 | 291 | $ hg phase -r . |
|
292 | 292 | 11: draft |
|
293 | 293 | $ hg commit -m 'update ab again' |
|
294 | 294 | |
|
295 | 295 | Phase is preserved |
|
296 | 296 | |
|
297 | 297 | $ hg uncommit --keep --config phases.new-commit=secret |
|
298 | 298 | note: keeping empty commit |
|
299 | 299 | $ hg phase -r . |
|
300 | 300 | 14: draft |
|
301 | 301 | $ hg commit --amend -m 'update ab again' |
|
302 | 302 | |
|
303 | 303 | Uncommit with public parent |
|
304 | 304 | |
|
305 | 305 | $ hg phase -p "::.^" |
|
306 | 306 | $ hg uncommit |
|
307 | 307 | $ hg phase -r . |
|
308 | 308 | 11: public |
|
309 | 309 | |
|
310 | 310 | Partial uncommit with public parent |
|
311 | 311 | |
|
312 | 312 | $ echo xyz > xyz |
|
313 | 313 | $ hg add xyz |
|
314 | 314 | $ hg commit -m "update ab and add xyz" |
|
315 | 315 | $ hg uncommit xyz |
|
316 | 316 | $ hg status |
|
317 | 317 | A xyz |
|
318 | 318 | $ hg phase -r . |
|
319 | 319 | 17: draft |
|
320 | 320 | $ hg phase -r ".^" |
|
321 | 321 | 11: public |
|
322 | 322 | |
|
323 | 323 | Uncommit with --keep or experimental.uncommit.keep leaves an empty changeset |
|
324 | 324 | |
|
325 | 325 | $ cd $TESTTMP |
|
326 | 326 | $ hg init repo1 |
|
327 | 327 | $ cd repo1 |
|
328 | 328 | $ hg debugdrawdag <<'EOS' |
|
329 | 329 | > Q |
|
330 | 330 | > | |
|
331 | 331 | > P |
|
332 | 332 | > EOS |
|
333 | 333 | $ hg up Q -q |
|
334 | 334 | $ hg uncommit --keep |
|
335 | 335 | note: keeping empty commit |
|
336 | 336 | $ hg log -G -T '{desc} FILES: {files}' |
|
337 | 337 | @ Q FILES: |
|
338 | 338 | | |
|
339 | 339 | | x Q FILES: Q |
|
340 | 340 | |/ |
|
341 | 341 | o P FILES: P |
|
342 | 342 | |
|
343 | 343 | $ cat >> .hg/hgrc <<EOF |
|
344 | 344 | > [experimental] |
|
345 | 345 | > uncommit.keep=True |
|
346 | 346 | > EOF |
|
347 | 347 | $ hg ci --amend |
|
348 | 348 | $ hg uncommit |
|
349 | 349 | note: keeping empty commit |
|
350 | 350 | $ hg log -G -T '{desc} FILES: {files}' |
|
351 | 351 | @ Q FILES: |
|
352 | 352 | | |
|
353 | 353 | | x Q FILES: Q |
|
354 | 354 | |/ |
|
355 | 355 | o P FILES: P |
|
356 | 356 | |
|
357 | 357 | $ hg status |
|
358 | 358 | A Q |
|
359 | 359 | $ hg ci --amend |
|
360 | 360 | $ hg uncommit --no-keep |
|
361 | 361 | $ hg log -G -T '{desc} FILES: {files}' |
|
362 | 362 | x Q FILES: Q |
|
363 | 363 | | |
|
364 | 364 | @ P FILES: P |
|
365 | 365 | |
|
366 | 366 | $ hg status |
|
367 | 367 | A Q |
|
368 | 368 | $ cd .. |
|
369 | 369 | $ rm -rf repo1 |
|
370 | 370 | |
|
371 | 371 | Testing uncommit while merge |
|
372 | 372 | |
|
373 | 373 | $ hg init repo2 |
|
374 | 374 | $ cd repo2 |
|
375 | 375 | |
|
376 | 376 | Create some history |
|
377 | 377 | |
|
378 | 378 | $ touch a |
|
379 | 379 | $ hg add a |
|
380 | 380 | $ for i in 1 2 3; do echo $i > a; hg commit -m "a $i"; done |
|
381 | 381 | $ hg checkout 0 |
|
382 | 382 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
383 | 383 | $ touch b |
|
384 | 384 | $ hg add b |
|
385 | 385 | $ for i in 1 2 3; do echo $i > b; hg commit -m "b $i"; done |
|
386 | 386 | created new head |
|
387 | 387 | $ hg log -G -T '{rev}:{node} {desc}' --hidden |
|
388 | 388 | @ 5:2cd56cdde163ded2fbb16ba2f918c96046ab0bf2 b 3 |
|
389 | 389 | | |
|
390 | 390 | o 4:c3a0d5bb3b15834ffd2ef9ef603e93ec65cf2037 b 2 |
|
391 | 391 | | |
|
392 | 392 | o 3:49bb009ca26078726b8870f1edb29fae8f7618f5 b 1 |
|
393 | 393 | | |
|
394 | 394 | | o 2:990982b7384266e691f1bc08ca36177adcd1c8a9 a 3 |
|
395 | 395 | | | |
|
396 | 396 | | o 1:24d38e3cf160c7b6f5ffe82179332229886a6d34 a 2 |
|
397 | 397 | |/ |
|
398 | 398 | o 0:ea4e33293d4d274a2ba73150733c2612231f398c a 1 |
|
399 | 399 | |
|
400 | 400 | |
|
401 | 401 | Add and expect uncommit to fail on both merge working dir and merge changeset |
|
402 | 402 | |
|
403 | 403 | $ hg merge 2 |
|
404 | 404 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
405 | 405 | (branch merge, don't forget to commit) |
|
406 | 406 | |
|
407 | 407 | $ hg uncommit |
|
408 | 408 | abort: outstanding uncommitted merge |
|
409 | 409 | (requires --allow-dirty-working-copy to uncommit) |
|
410 | 410 | [20] |
|
411 | 411 | |
|
412 | 412 | $ hg uncommit --config experimental.uncommitondirtywdir=True |
|
413 | 413 | abort: cannot uncommit while merging |
|
414 | 414 | [20] |
|
415 | 415 | |
|
416 | 416 | $ hg status |
|
417 | 417 | M a |
|
418 | 418 | $ hg commit -m 'merge a and b' |
|
419 | 419 | |
|
420 | 420 | $ hg uncommit |
|
421 | 421 | abort: cannot uncommit merge changeset |
|
422 | 422 | [10] |
|
423 | 423 | |
|
424 | 424 | $ hg status |
|
425 | 425 | $ hg log -G -T '{rev}:{node} {desc}' --hidden |
|
426 | 426 | @ 6:c03b9c37bc67bf504d4912061cfb527b47a63c6e merge a and b |
|
427 | 427 | |\ |
|
428 | 428 | | o 5:2cd56cdde163ded2fbb16ba2f918c96046ab0bf2 b 3 |
|
429 | 429 | | | |
|
430 | 430 | | o 4:c3a0d5bb3b15834ffd2ef9ef603e93ec65cf2037 b 2 |
|
431 | 431 | | | |
|
432 | 432 | | o 3:49bb009ca26078726b8870f1edb29fae8f7618f5 b 1 |
|
433 | 433 | | | |
|
434 | 434 | o | 2:990982b7384266e691f1bc08ca36177adcd1c8a9 a 3 |
|
435 | 435 | | | |
|
436 | 436 | o | 1:24d38e3cf160c7b6f5ffe82179332229886a6d34 a 2 |
|
437 | 437 | |/ |
|
438 | 438 | o 0:ea4e33293d4d274a2ba73150733c2612231f398c a 1 |
|
439 | 439 | |
|
440 | 440 | |
|
441 | 441 | Rename a->b, then remove b in working copy. Result should remove a. |
|
442 | 442 | |
|
443 | 443 | $ hg co -q 0 |
|
444 | 444 | $ hg mv a b |
|
445 | 445 | $ hg ci -qm 'move a to b' |
|
446 | 446 | $ hg rm b |
|
447 | 447 | $ hg uncommit --config experimental.uncommitondirtywdir=True |
|
448 | 448 | $ hg st --copies |
|
449 | 449 | R a |
|
450 | 450 | $ hg revert a |
|
451 | 451 | |
|
452 | 452 | Rename a->b, then rename b->c in working copy. Result should rename a->c. |
|
453 | 453 | |
|
454 | 454 | $ hg co -q 0 |
|
455 | 455 | $ hg mv a b |
|
456 | 456 | $ hg ci -qm 'move a to b' |
|
457 | 457 | $ hg mv b c |
|
458 | 458 | $ hg uncommit --config experimental.uncommitondirtywdir=True |
|
459 | 459 | $ hg st --copies |
|
460 | 460 | A c |
|
461 | 461 | a |
|
462 | 462 | R a |
|
463 | 463 | $ hg revert a |
|
464 | 464 | $ hg forget c |
|
465 | 465 | $ rm c |
|
466 | 466 | |
|
467 | 467 | Copy a->b1 and a->b2, then rename b1->c in working copy. Result should copy a->b2 and a->c. |
|
468 | 468 | |
|
469 | 469 | $ hg co -q 0 |
|
470 | 470 | $ hg cp a b1 |
|
471 | 471 | $ hg cp a b2 |
|
472 | 472 | $ hg ci -qm 'move a to b1 and b2' |
|
473 | 473 | $ hg mv b1 c |
|
474 | 474 | $ hg uncommit --config experimental.uncommitondirtywdir=True |
|
475 | 475 | $ hg st --copies |
|
476 | 476 | A b2 |
|
477 | 477 | a |
|
478 | 478 | A c |
|
479 | 479 | a |
|
480 | 480 | $ cd .. |
|
481 | 481 | |
|
482 | 482 | --allow-dirty-working-copy should also work on a dirty PATH |
|
483 | 483 | |
|
484 | 484 | $ hg init issue5977 |
|
485 | 485 | $ cd issue5977 |
|
486 | 486 | $ echo 'super critical info!' > a |
|
487 | 487 | $ hg ci -Am 'add a' |
|
488 | 488 | adding a |
|
489 | 489 | $ echo 'foo' > b |
|
490 | 490 | $ hg add b |
|
491 | 491 | $ hg status |
|
492 | 492 | A b |
|
493 | 493 | $ hg uncommit a |
|
494 | 494 | note: keeping empty commit |
|
495 | 495 | $ cat a |
|
496 | 496 | super critical info! |
|
497 | 497 | $ hg log |
|
498 | 498 | changeset: 1:656ba143d384 |
|
499 | 499 | tag: tip |
|
500 | 500 | parent: -1:000000000000 |
|
501 | 501 | user: test |
|
502 | 502 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
503 | 503 | summary: add a |
|
504 | 504 | |
|
505 | 505 | $ hg ci -Am 'add b' |
|
506 | 506 | $ echo 'foo bar' > b |
|
507 | 507 | $ hg uncommit b |
|
508 | 508 | abort: uncommitted changes |
|
509 | 509 | (requires --allow-dirty-working-copy to uncommit) |
|
510 | 510 | [20] |
|
511 | 511 | $ hg uncommit --allow-dirty-working-copy b |
|
512 | 512 | $ hg log |
|
513 | 513 | changeset: 3:30fa958635b2 |
|
514 | 514 | tag: tip |
|
515 | 515 | parent: 1:656ba143d384 |
|
516 | 516 | user: test |
|
517 | 517 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
518 | 518 | summary: add b |
|
519 | 519 | |
|
520 | 520 | changeset: 1:656ba143d384 |
|
521 | 521 | parent: -1:000000000000 |
|
522 | 522 | user: test |
|
523 | 523 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
524 | 524 | summary: add a |
|
525 | 525 | |
|
526 | 526 | Removes can be uncommitted |
|
527 | 527 | |
|
528 | 528 | $ hg ci -m 'modified b' |
|
529 | 529 | $ hg rm b |
|
530 | 530 | $ hg ci -m 'remove b' |
|
531 | 531 | $ hg uncommit b |
|
532 | 532 | note: keeping empty commit |
|
533 | 533 | $ hg status |
|
534 | 534 | R b |
|
535 | 535 | |
|
536 | 536 | Uncommitting a directory won't run afoul of the checks that an explicit file |
|
537 | 537 | can be uncommitted. |
|
538 | 538 | |
|
539 | 539 | $ mkdir dir |
|
540 | 540 | $ echo 1 > dir/file.txt |
|
541 | 541 | $ hg ci -Aqm 'add file in directory' |
|
542 | 542 | $ hg uncommit dir -m 'uncommit with message' -u 'different user' \ |
|
543 | 543 | > -d 'Jun 30 12:12:12 1980 +0000' |
|
544 | 544 | $ hg status |
|
545 | 545 | A dir/file.txt |
|
546 | 546 | $ hg log -r . |
|
547 | 547 | changeset: 8:b4dd26dc42e0 |
|
548 | 548 | tag: tip |
|
549 | 549 | parent: 6:2278a4c24330 |
|
550 | 550 | user: different user |
|
551 | 551 | date: Mon Jun 30 12:12:12 1980 +0000 |
|
552 | 552 | summary: uncommit with message |
|
553 | 553 | |
|
554 | 554 | Bad option combinations |
|
555 | 555 | |
|
556 | 556 | $ hg rollback -q --config ui.rollback=True |
|
557 | 557 | $ hg uncommit -U --user 'user' |
|
558 | 558 | abort: cannot specify both --user and --currentuser |
|
559 | 559 | [10] |
|
560 | 560 | $ hg uncommit -D --date today |
|
561 | 561 | abort: cannot specify both --date and --currentdate |
|
562 | 562 | [10] |
|
563 | 563 | |
|
564 | 564 | `uncommit <dir>` and `cd <dir> && uncommit .` behave the same... |
|
565 | 565 | |
|
566 | 566 | $ echo 2 > dir/file2.txt |
|
567 | 567 | $ hg ci -Aqm 'add file2 in directory' |
|
568 | 568 | $ hg uncommit dir |
|
569 | 569 | note: keeping empty commit |
|
570 | 570 | $ hg status |
|
571 | 571 | A dir/file2.txt |
|
572 | 572 | |
|
573 | 573 | $ hg rollback -q --config ui.rollback=True |
|
574 | 574 | $ cd dir |
|
575 | 575 | $ hg uncommit . -n 'this is a note' |
|
576 | 576 | note: keeping empty commit |
|
577 | 577 | $ hg status |
|
578 | 578 | A dir/file2.txt |
|
579 | 579 | $ cd .. |
|
580 | 580 | |
|
581 | 581 | ... and errors out the same way when nothing can be uncommitted |
|
582 | 582 | |
|
583 | 583 | $ hg rollback -q --config ui.rollback=True |
|
584 | 584 | $ mkdir emptydir |
|
585 | 585 | $ hg uncommit emptydir |
|
586 | 586 | abort: cannot uncommit "emptydir" |
|
587 | 587 | (file was untracked in working directory parent) |
|
588 | 588 | [10] |
|
589 | 589 | |
|
590 | 590 | $ cd emptydir |
|
591 | 591 | $ hg uncommit . |
|
592 | 592 | abort: cannot uncommit "emptydir" |
|
593 | 593 | (file was untracked in working directory parent) |
|
594 | 594 | [10] |
|
595 | 595 | $ hg status |
|
596 | 596 | $ cd .. |
General Comments 0
You need to be logged in to leave comments.
Login now