# HG changeset patch # User Alexis S. L. Carvalho # Date 1183442800 10800 # Node ID 44e17f5029d05bb60cacd37ab6a6f06574c44b1d # Parent 719c402258ee2db91e7de477c8ac61d674fe0e2a 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. diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -466,18 +466,17 @@ def docopy(ui, repo, pats, opts, wlock): # 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 @@ def docopy(ui, repo, pats, opts, wlock): 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 diff --git a/tests/test-copy2 b/tests/test-copy2 --- a/tests/test-copy2 +++ b/tests/test-copy2 @@ -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 diff --git a/tests/test-copy2.out b/tests/test-copy2.out --- a/tests/test-copy2.out +++ b/tests/test-copy2.out @@ -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