comparison hgext/uncommit.py @ 42051:f4147ca63d39

uncommit: abort if an explicitly given file cannot be uncommitted (BC) I've gotten burned several times by this in the last few days. The former tests look simple enough, but if a good file and a bad file are given, the bad files are silently ignored. Some commands like `forget` will warn about bogus files, but that would likely get lost in the noise of an interactive uncommit. The commit command aborts if a bad file is given, so this seems more consistent for commands that alter the repository.
author Matt Harbison <matt_harbison@yahoo.com>
date Fri, 29 Mar 2019 21:53:15 -0400
parents 550a172a603b
children 566daffc607d
comparison
equal deleted inserted replaced
42050:03f6480bfdda 42051:f4147ca63d39
31 obsutil, 31 obsutil,
32 pycompat, 32 pycompat,
33 registrar, 33 registrar,
34 rewriteutil, 34 rewriteutil,
35 scmutil, 35 scmutil,
36 util,
36 ) 37 )
37 38
38 cmdtable = {} 39 cmdtable = {}
39 command = registrar.command(cmdtable) 40 command = registrar.command(cmdtable)
40 41
131 old = repo['.'] 132 old = repo['.']
132 rewriteutil.precheck(repo, [old.rev()], 'uncommit') 133 rewriteutil.precheck(repo, [old.rev()], 'uncommit')
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:
141 keepcommit = opts.get('keep') 168 keepcommit = opts.get('keep')
142 else: 169 else: