Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/cmdutil.py @ 39377:5b92a717bfc1
rename: return error status if any rename/copy failed
Ever since 447ea621e50e (copy: propagate errors properly, 2007-12-06),
we have returned an error status if the source file did not
exist. That commit did not return error status for any other errors,
and it's unclear if that was on purpose or not. It seems to me like we
should return an error in the other cases to, so that's what this
patch does.
Differential Revision: https://phab.mercurial-scm.org/D4419
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Wed, 29 Aug 2018 09:59:08 -0700 |
parents | 534e451b6dda |
children | 34ba47117164 |
comparison
equal
deleted
inserted
replaced
39376:534e451b6dda | 39377:5b92a717bfc1 |
---|---|
1182 prevsrc = targets.get(abstarget) | 1182 prevsrc = targets.get(abstarget) |
1183 if prevsrc is not None: | 1183 if prevsrc is not None: |
1184 ui.warn(_('%s: not overwriting - %s collides with %s\n') % | 1184 ui.warn(_('%s: not overwriting - %s collides with %s\n') % |
1185 (reltarget, repo.pathto(abssrc, cwd), | 1185 (reltarget, repo.pathto(abssrc, cwd), |
1186 repo.pathto(prevsrc, cwd))) | 1186 repo.pathto(prevsrc, cwd))) |
1187 return | 1187 return True # report a failure |
1188 | 1188 |
1189 # check for overwrites | 1189 # check for overwrites |
1190 exists = os.path.lexists(target) | 1190 exists = os.path.lexists(target) |
1191 samefile = False | 1191 samefile = False |
1192 if exists and abssrc != abstarget: | 1192 if exists and abssrc != abstarget: |
1193 if (repo.dirstate.normalize(abssrc) == | 1193 if (repo.dirstate.normalize(abssrc) == |
1194 repo.dirstate.normalize(abstarget)): | 1194 repo.dirstate.normalize(abstarget)): |
1195 if not rename: | 1195 if not rename: |
1196 ui.warn(_("%s: can't copy - same file\n") % reltarget) | 1196 ui.warn(_("%s: can't copy - same file\n") % reltarget) |
1197 return | 1197 return True # report a failure |
1198 exists = False | 1198 exists = False |
1199 samefile = True | 1199 samefile = True |
1200 | 1200 |
1201 if not after and exists or after and state in 'mn': | 1201 if not after and exists or after and state in 'mn': |
1202 if not opts['force']: | 1202 if not opts['force']: |
1218 hint = _("('hg rename --after' to record the rename)\n") | 1218 hint = _("('hg rename --after' to record the rename)\n") |
1219 else: | 1219 else: |
1220 hint = _("('hg copy --after' to record the copy)\n") | 1220 hint = _("('hg copy --after' to record the copy)\n") |
1221 ui.warn(msg % reltarget) | 1221 ui.warn(msg % reltarget) |
1222 ui.warn(hint) | 1222 ui.warn(hint) |
1223 return | 1223 return True # report a failure |
1224 | 1224 |
1225 if after: | 1225 if after: |
1226 if not exists: | 1226 if not exists: |
1227 if rename: | 1227 if rename: |
1228 ui.warn(_('%s: not recording move - %s does not exist\n') % | 1228 ui.warn(_('%s: not recording move - %s does not exist\n') % |
1229 (relsrc, reltarget)) | 1229 (relsrc, reltarget)) |
1230 else: | 1230 else: |
1231 ui.warn(_('%s: not recording copy - %s does not exist\n') % | 1231 ui.warn(_('%s: not recording copy - %s does not exist\n') % |
1232 (relsrc, reltarget)) | 1232 (relsrc, reltarget)) |
1233 return | 1233 return True # report a failure |
1234 elif not dryrun: | 1234 elif not dryrun: |
1235 try: | 1235 try: |
1236 if exists: | 1236 if exists: |
1237 os.unlink(target) | 1237 os.unlink(target) |
1238 targetdir = os.path.dirname(target) or '.' | 1238 targetdir = os.path.dirname(target) or '.' |