Mercurial > hg
changeset 4744:44e17f5029d0
Make hg add foo; hg mv foo bar work.
- foo will be removed (the user has a copy of its contents in bar)
- bar will not be marked as a copy (there was no committed version of foo).
We print a warning telling that to the user.
Fixes issue269.
author | Alexis S. L. Carvalho <alexis@cecm.usp.br> |
---|---|
date | Tue, 03 Jul 2007 03:06:40 -0300 |
parents | 719c402258ee |
children | e21a0e12ff10 |
files | mercurial/commands.py tests/test-copy2 tests/test-copy2.out |
diffstat | 3 files changed, 44 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/commands.py Tue Jul 03 03:06:40 2007 -0300 +++ b/mercurial/commands.py Tue Jul 03 03:06:40 2007 -0300 @@ -466,18 +466,17 @@ # return: hgsep def okaytocopy(abs, rel, exact): reasons = {'?': _('is not managed'), - 'a': _('has been marked for add'), 'r': _('has been marked for remove')} state = repo.dirstate.state(abs) reason = reasons.get(state) if reason: + if exact: + ui.warn(_('%s: not copying - file %s\n') % (rel, reason)) + else: if state == 'a': origsrc = repo.dirstate.copied(abs) if origsrc is not None: return origsrc - if exact: - ui.warn(_('%s: not copying - file %s\n') % (rel, reason)) - else: return abs # origsrc: hgsep @@ -532,8 +531,15 @@ if ui.verbose or not exact: ui.status(_('copying %s to %s\n') % (relsrc, reltarget)) targets[abstarget] = abssrc - if abstarget != origsrc and not opts.get('dry_run'): - repo.copy(origsrc, abstarget, wlock) + if abstarget != origsrc: + if repo.dirstate.state(origsrc) == 'a': + ui.warn(_("%s was marked for addition. " + "%s will not be committed as a copy.\n") + % (repo.pathto(origsrc, cwd), reltarget)) + if abstarget not in repo.dirstate and not opts.get('dry_run'): + repo.add([abstarget], wlock) + elif not opts.get('dry_run'): + repo.copy(origsrc, abstarget, wlock) copied.append((abssrc, relsrc, exact)) # pat: ossep
--- a/tests/test-copy2 Tue Jul 03 03:06:40 2007 -0300 +++ b/tests/test-copy2 Tue Jul 03 03:06:40 2007 -0300 @@ -2,9 +2,26 @@ hg init echo foo > foo +echo "# should fail - foo is not managed" +hg mv foo bar +hg st -A hg add foo +echo "# dry-run; print a warning that this is not a real copy; foo is added" +hg mv --dry-run foo bar +hg st -A +echo "# should print a warning that this is not a real copy; bar is added" +hg mv foo bar +hg st -A +echo "# should print a warning that this is not a real copy; foo is added" +hg cp bar foo +hg rm -f bar +rm bar +hg st -A hg commit -m1 -d"0 0" +echo "# dry-run; should show that foo is clean" +hg copy --dry-run foo bar +hg st -A echo "# should show copy" hg copy foo bar hg st -C
--- a/tests/test-copy2.out Tue Jul 03 03:06:40 2007 -0300 +++ b/tests/test-copy2.out Tue Jul 03 03:06:40 2007 -0300 @@ -1,3 +1,18 @@ +# should fail - foo is not managed +foo: not copying - file is not managed +abort: no files to copy +? foo +# dry-run; print a warning that this is not a real copy; foo is added +foo was marked for addition. bar will not be committed as a copy. +A foo +# should print a warning that this is not a real copy; bar is added +foo was marked for addition. bar will not be committed as a copy. +A bar +# should print a warning that this is not a real copy; foo is added +bar was marked for addition. foo will not be committed as a copy. +A foo +# dry-run; should show that foo is clean +C foo # should show copy A bar foo