##// 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 to the named files or directories. This restores the contents of
2287 to the named files or directories. This restores the contents of
2288 the affected files to an unmodified state.
2288 the affected files to an unmodified state.
2289
2289
2290 Modified files have backup copies saved before revert. To disable
2290 Modified files are saved with a .orig suffix before reverting.
2291 backups, use --no-backup. To change the name of backup files, use
2291 To disable these backups, use --no-backup.
2292 --backup to give a format string.
2293
2292
2294 Using the -r option, it reverts the given files or directories to
2293 Using the -r option, it reverts the given files or directories to
2295 their state as of an earlier revision. This can be helpful to "roll
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 node = opts['rev'] and repo.lookup(opts['rev']) or parent
2308 node = opts['rev'] and repo.lookup(opts['rev']) or parent
2310 mf = repo.manifest.read(repo.changelog.read(node)[0])
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 wlock = repo.wlock()
2311 wlock = repo.wlock()
2331
2312
2332 entries = []
2313 entries = []
@@ -2362,8 +2343,12 b' def revert(ui, repo, *pats, **opts):'
2362 for abs, rel, exact in entries:
2343 for abs, rel, exact in entries:
2363 def handle(xlist, dobackup):
2344 def handle(xlist, dobackup):
2364 xlist[0].append(abs)
2345 xlist[0].append(abs)
2365 if dobackup and not opts['no_backup']:
2346 if dobackup and not opts['no_backup'] and os.path.exists(rel):
2366 backup(rel, exact)
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 if ui.verbose or not exact:
2352 if ui.verbose or not exact:
2368 ui.status(xlist[1] % rel)
2353 ui.status(xlist[1] % rel)
2369 for table, hitlist, misslist, backuphit, backupmiss in disptable:
2354 for table, hitlist, misslist, backuphit, backupmiss in disptable:
@@ -3011,7 +2996,6 b' table = {'
3011 "^revert":
2996 "^revert":
3012 (revert,
2997 (revert,
3013 [('r', 'rev', '', _('revision to revert to')),
2998 [('r', 'rev', '', _('revision to revert to')),
3014 ('', 'backup-name', '', _('save backup with formatted name')),
3015 ('', 'no-backup', None, _('do not save backup copies of files')),
2999 ('', 'no-backup', None, _('do not save backup copies of files')),
3016 ('I', 'include', [], _('include names matching given patterns')),
3000 ('I', 'include', [], _('include names matching given patterns')),
3017 ('X', 'exclude', [], _('exclude names matching given patterns'))],
3001 ('X', 'exclude', [], _('exclude names matching given patterns'))],
@@ -2,7 +2,6 b''
2 A b
2 A b
3 R a
3 R a
4 reverting...
4 reverting...
5 saving current version of b as b.orig
6 forgetting b
5 forgetting b
7 undeleting a
6 undeleting a
8 %%% should show b unknown and a back to normal
7 %%% should show b unknown and a back to normal
@@ -3,7 +3,6 b' 0:eb43f19ff115'
3 016807e6fdaf tip
3 016807e6fdaf tip
4 eb43f19ff115
4 eb43f19ff115
5 eb43f19ff115+
5 eb43f19ff115+
6 saving current version of file1 as file1.orig
7 reverting file1
6 reverting file1
8 ? file1.orig
7 ? file1.orig
9 eb43f19ff115
8 eb43f19ff115
@@ -22,16 +22,16 b' hg revert a'
22 echo %% should show b added, copy saved, and c modified
22 echo %% should show b added, copy saved, and c modified
23 hg status
23 hg status
24 hg revert b
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 hg status
26 hg status
27 hg revert --no-backup c
27 hg revert --no-backup c
28 echo %% should show unknown: b b.bak
28 echo %% should show unknown: b b.orig
29 hg status
29 hg status
30 echo %% should show a b b.bak c e
30 echo %% should show a b b.orig c e
31 ls
31 ls
32 echo %% should save backup to e.0
32 echo %% should verbosely save backup to e.orig
33 echo z > e
33 echo z > e
34 hg revert --backup='%p.%R'
34 hg revert -v
35 echo %% should say no changes needed
35 echo %% should say no changes needed
36 hg revert a
36 hg revert a
37 echo %% should say file not managed
37 echo %% should say file not managed
@@ -13,23 +13,25 b' R a'
13 %% should show b added, copy saved, and c modified
13 %% should show b added, copy saved, and c modified
14 M c
14 M c
15 A b
15 A b
16 saving current version of b as b.orig
16 %% should show b unknown, b.orig unknown, and c modified
17 %% should show b unknown, b.bak unknown, and c modified
18 M c
17 M c
19 ? b
18 ? b
20 ? b.orig
19 ? b.orig
21 %% should show unknown: b b.bak
20 %% should show unknown: b b.orig
22 ? b
21 ? b
23 ? b.orig
22 ? b.orig
24 %% should show a b b.bak c e
23 %% should show a b b.orig c e
25 a
24 a
26 b
25 b
27 b.orig
26 b.orig
28 c
27 c
29 e
28 e
30 %% should save backup to e.0
29 %% should verbosely save backup to e.orig
31 saving current version of e as e.0
30 saving current version of e as e.orig
32 reverting e
31 reverting e
32 resolving manifests
33 getting e
34 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
33 %% should say no changes needed
35 %% should say no changes needed
34 no changes needed to a
36 no changes needed to a
35 %% should say file not managed
37 %% should say file not managed
@@ -21,7 +21,6 b' failed'
21 use of 'hg tag NAME [REV]' is deprecated, please use 'hg tag [-r REV] NAME' instead
21 use of 'hg tag NAME [REV]' is deprecated, please use 'hg tag [-r REV] NAME' instead
22 abort: use only one form to specify the revision
22 abort: use only one form to specify the revision
23 failed
23 failed
24 saving current version of .hgtags as .hgtags.orig
25 use of 'hg tag NAME [REV]' is deprecated, please use 'hg tag [-r REV] NAME' instead
24 use of 'hg tag NAME [REV]' is deprecated, please use 'hg tag [-r REV] NAME' instead
26 0acdaf8983679e0aac16e811534eb49d7ee1f2b4 bleah
25 0acdaf8983679e0aac16e811534eb49d7ee1f2b4 bleah
27 0acdaf8983679e0aac16e811534eb49d7ee1f2b4 bleah0
26 0acdaf8983679e0aac16e811534eb49d7ee1f2b4 bleah0
General Comments 0
You need to be logged in to leave comments. Login now