##// END OF EJS Templates
Don't abort when backup files already exist. Don't allow alternative names....
Thomas Arendsen Hein -
r2036:c9226bcc default
parent child Browse files
Show More
@@ -2287,9 +2287,8 b' def revert(ui, repo, *pats, **opts):'
2287 2287 to the named files or directories. This restores the contents of
2288 2288 the affected files to an unmodified state.
2289 2289
2290 Modified files have backup copies saved before revert. To disable
2291 backups, use --no-backup. To change the name of backup files, use
2292 --backup to give a format string.
2290 Modified files are saved with a .orig suffix before reverting.
2291 To disable these backups, use --no-backup.
2293 2292
2294 2293 Using the -r option, it reverts the given files or directories to
2295 2294 their state as of an earlier revision. This can be helpful to "roll
@@ -2309,24 +2308,6 b' def revert(ui, repo, *pats, **opts):'
2309 2308 node = opts['rev'] and repo.lookup(opts['rev']) or parent
2310 2309 mf = repo.manifest.read(repo.changelog.read(node)[0])
2311 2310
2312 def backup(name, exact):
2313 bakname = make_filename(repo, repo.changelog,
2314 opts['backup_name'] or '%p.orig',
2315 node=parent, pathname=name)
2316 if os.path.exists(name):
2317 # if backup already exists and is same as backup we want
2318 # to make, do nothing
2319 if os.path.exists(bakname):
2320 if repo.wread(name) == repo.wread(bakname):
2321 return
2322 raise util.Abort(_('cannot save current version of %s - '
2323 '%s exists and differs') %
2324 (name, bakname))
2325 ui.status(('saving current version of %s as %s\n') %
2326 (name, bakname))
2327 shutil.copyfile(name, bakname)
2328 shutil.copymode(name, bakname)
2329
2330 2311 wlock = repo.wlock()
2331 2312
2332 2313 entries = []
@@ -2362,8 +2343,12 b' def revert(ui, repo, *pats, **opts):'
2362 2343 for abs, rel, exact in entries:
2363 2344 def handle(xlist, dobackup):
2364 2345 xlist[0].append(abs)
2365 if dobackup and not opts['no_backup']:
2366 backup(rel, exact)
2346 if dobackup and not opts['no_backup'] and os.path.exists(rel):
2347 bakname = "%s.orig" % rel
2348 ui.note(_('saving current version of %s as %s\n') %
2349 (rel, bakname))
2350 shutil.copyfile(rel, bakname)
2351 shutil.copymode(rel, bakname)
2367 2352 if ui.verbose or not exact:
2368 2353 ui.status(xlist[1] % rel)
2369 2354 for table, hitlist, misslist, backuphit, backupmiss in disptable:
@@ -3011,7 +2996,6 b' table = {'
3011 2996 "^revert":
3012 2997 (revert,
3013 2998 [('r', 'rev', '', _('revision to revert to')),
3014 ('', 'backup-name', '', _('save backup with formatted name')),
3015 2999 ('', 'no-backup', None, _('do not save backup copies of files')),
3016 3000 ('I', 'include', [], _('include names matching given patterns')),
3017 3001 ('X', 'exclude', [], _('exclude names matching given patterns'))],
@@ -2,7 +2,6 b''
2 2 A b
3 3 R a
4 4 reverting...
5 saving current version of b as b.orig
6 5 forgetting b
7 6 undeleting a
8 7 %%% should show b unknown and a back to normal
@@ -3,7 +3,6 b' 0:eb43f19ff115'
3 3 016807e6fdaf tip
4 4 eb43f19ff115
5 5 eb43f19ff115+
6 saving current version of file1 as file1.orig
7 6 reverting file1
8 7 ? file1.orig
9 8 eb43f19ff115
@@ -22,16 +22,16 b' hg revert a'
22 22 echo %% should show b added, copy saved, and c modified
23 23 hg status
24 24 hg revert b
25 echo %% should show b unknown, b.bak unknown, and c modified
25 echo %% should show b unknown, b.orig unknown, and c modified
26 26 hg status
27 27 hg revert --no-backup c
28 echo %% should show unknown: b b.bak
28 echo %% should show unknown: b b.orig
29 29 hg status
30 echo %% should show a b b.bak c e
30 echo %% should show a b b.orig c e
31 31 ls
32 echo %% should save backup to e.0
32 echo %% should verbosely save backup to e.orig
33 33 echo z > e
34 hg revert --backup='%p.%R'
34 hg revert -v
35 35 echo %% should say no changes needed
36 36 hg revert a
37 37 echo %% should say file not managed
@@ -13,23 +13,25 b' R a'
13 13 %% should show b added, copy saved, and c modified
14 14 M c
15 15 A b
16 saving current version of b as b.orig
17 %% should show b unknown, b.bak unknown, and c modified
16 %% should show b unknown, b.orig unknown, and c modified
18 17 M c
19 18 ? b
20 19 ? b.orig
21 %% should show unknown: b b.bak
20 %% should show unknown: b b.orig
22 21 ? b
23 22 ? b.orig
24 %% should show a b b.bak c e
23 %% should show a b b.orig c e
25 24 a
26 25 b
27 26 b.orig
28 27 c
29 28 e
30 %% should save backup to e.0
31 saving current version of e as e.0
29 %% should verbosely save backup to e.orig
30 saving current version of e as e.orig
32 31 reverting e
32 resolving manifests
33 getting e
34 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
33 35 %% should say no changes needed
34 36 no changes needed to a
35 37 %% should say file not managed
@@ -21,7 +21,6 b' failed'
21 21 use of 'hg tag NAME [REV]' is deprecated, please use 'hg tag [-r REV] NAME' instead
22 22 abort: use only one form to specify the revision
23 23 failed
24 saving current version of .hgtags as .hgtags.orig
25 24 use of 'hg tag NAME [REV]' is deprecated, please use 'hg tag [-r REV] NAME' instead
26 25 0acdaf8983679e0aac16e811534eb49d7ee1f2b4 bleah
27 26 0acdaf8983679e0aac16e811534eb49d7ee1f2b4 bleah0
General Comments 0
You need to be logged in to leave comments. Login now