Show More
@@ -33,6 +33,7 b' from mercurial import (' | |||||
33 | registrar, |
|
33 | registrar, | |
34 | rewriteutil, |
|
34 | rewriteutil, | |
35 | scmutil, |
|
35 | scmutil, | |
|
36 | util, | |||
36 | ) |
|
37 | ) | |
37 |
|
38 | |||
38 | cmdtable = {} |
|
39 | cmdtable = {} | |
@@ -133,8 +134,34 b' def uncommit(ui, repo, *pats, **opts):' | |||||
133 | if len(old.parents()) > 1: |
|
134 | if len(old.parents()) > 1: | |
134 | raise error.Abort(_("cannot uncommit merge changeset")) |
|
135 | raise error.Abort(_("cannot uncommit merge changeset")) | |
135 |
|
136 | |||
|
137 | match = scmutil.match(old, pats, opts) | |||
|
138 | ||||
|
139 | # Check all explicitly given files; abort if there's a problem. | |||
|
140 | if match.files(): | |||
|
141 | s = old.status(old.p1(), match, listclean=True) | |||
|
142 | eligible = set(s.added) | set(s.modified) | set(s.removed) | |||
|
143 | ||||
|
144 | badfiles = set(match.files()) - eligible | |||
|
145 | ||||
|
146 | # Naming a parent directory of an eligible file is OK, even | |||
|
147 | # if not everything tracked in that directory can be | |||
|
148 | # uncommitted. | |||
|
149 | if badfiles: | |||
|
150 | badfiles -= set([f for f in util.dirs(eligible)]) | |||
|
151 | ||||
|
152 | for f in sorted(badfiles): | |||
|
153 | if f in s.clean: | |||
|
154 | hint = _(b"file was not changed in working directory " | |||
|
155 | b"parent") | |||
|
156 | elif repo.wvfs.exists(f): | |||
|
157 | hint = _(b"file was untracked in working directory parent") | |||
|
158 | else: | |||
|
159 | hint = _(b"file does not exist") | |||
|
160 | ||||
|
161 | raise error.Abort(_(b'cannot uncommit "%s"') | |||
|
162 | % scmutil.getuipathfn(repo)(f), hint=hint) | |||
|
163 | ||||
136 | with repo.transaction('uncommit'): |
|
164 | with repo.transaction('uncommit'): | |
137 | match = scmutil.match(old, pats, opts) |
|
|||
138 | keepcommit = pats |
|
165 | keepcommit = pats | |
139 | if not keepcommit: |
|
166 | if not keepcommit: | |
140 | if opts.get('keep') is not None: |
|
167 | if opts.get('keep') is not None: |
@@ -102,14 +102,16 b' Recommit' | |||||
102 | $ hg heads -T '{rev}:{node} {desc}' |
|
102 | $ hg heads -T '{rev}:{node} {desc}' | |
103 | 5:0c07a3ccda771b25f1cb1edbd02e683723344ef1 new change abcde (no-eol) |
|
103 | 5:0c07a3ccda771b25f1cb1edbd02e683723344ef1 new change abcde (no-eol) | |
104 |
|
104 | |||
105 |
Uncommit of non-existent and unchanged files |
|
105 | Uncommit of non-existent and unchanged files aborts | |
106 | $ hg uncommit nothinghere |
|
106 | $ hg uncommit nothinghere | |
107 | nothing to uncommit |
|
107 | abort: cannot uncommit "nothinghere" | |
108 | [1] |
|
108 | (file does not exist) | |
|
109 | [255] | |||
109 | $ hg status |
|
110 | $ hg status | |
110 | $ hg uncommit file-abc |
|
111 | $ hg uncommit file-abc | |
111 | nothing to uncommit |
|
112 | abort: cannot uncommit "file-abc" | |
112 | [1] |
|
113 | (file was not changed in working directory parent) | |
|
114 | [255] | |||
113 | $ hg status |
|
115 | $ hg status | |
114 |
|
116 | |||
115 | Try partial uncommit, also moves bookmark |
|
117 | Try partial uncommit, also moves bookmark | |
@@ -513,3 +515,57 b' Copy a->b1 and a->b2, then rename b1->c ' | |||||
513 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
515 | date: Thu Jan 01 00:00:00 1970 +0000 | |
514 | summary: add a |
|
516 | summary: add a | |
515 |
|
517 | |||
|
518 | Removes can be uncommitted | |||
|
519 | ||||
|
520 | $ hg ci -m 'modified b' | |||
|
521 | $ hg rm b | |||
|
522 | $ hg ci -m 'remove b' | |||
|
523 | $ hg uncommit b | |||
|
524 | note: keeping empty commit | |||
|
525 | $ hg status | |||
|
526 | R b | |||
|
527 | ||||
|
528 | Uncommitting a directory won't run afoul of the checks that an explicit file | |||
|
529 | can be uncommitted. | |||
|
530 | ||||
|
531 | $ mkdir dir | |||
|
532 | $ echo 1 > dir/file.txt | |||
|
533 | $ hg ci -Aqm 'add file in directory' | |||
|
534 | $ hg uncommit dir | |||
|
535 | $ hg status | |||
|
536 | A dir/file.txt | |||
|
537 | ||||
|
538 | `uncommit <dir>` and `cd <dir> && uncommit .` behave the same... | |||
|
539 | ||||
|
540 | $ hg rollback -q --config ui.rollback=True | |||
|
541 | $ echo 2 > dir/file2.txt | |||
|
542 | $ hg ci -Aqm 'add file2 in directory' | |||
|
543 | $ hg uncommit dir | |||
|
544 | note: keeping empty commit | |||
|
545 | $ hg status | |||
|
546 | A dir/file2.txt | |||
|
547 | ||||
|
548 | $ hg rollback -q --config ui.rollback=True | |||
|
549 | $ cd dir | |||
|
550 | $ hg uncommit . | |||
|
551 | note: keeping empty commit | |||
|
552 | $ hg status | |||
|
553 | A dir/file2.txt | |||
|
554 | $ cd .. | |||
|
555 | ||||
|
556 | ... and errors out the same way when nothing can be uncommitted | |||
|
557 | ||||
|
558 | $ hg rollback -q --config ui.rollback=True | |||
|
559 | $ mkdir emptydir | |||
|
560 | $ hg uncommit emptydir | |||
|
561 | abort: cannot uncommit "emptydir" | |||
|
562 | (file was untracked in working directory parent) | |||
|
563 | [255] | |||
|
564 | ||||
|
565 | $ cd emptydir | |||
|
566 | $ hg uncommit . | |||
|
567 | abort: cannot uncommit "emptydir" | |||
|
568 | (file was untracked in working directory parent) | |||
|
569 | [255] | |||
|
570 | $ hg status | |||
|
571 | $ cd .. |
General Comments 0
You need to be logged in to leave comments.
Login now