[PATCH] cmdutil: warn when trying to copy/rename -A to a nonexistent file (issue1822)
Steve Losh
steve at stevelosh.com
Sun May 2 14:15:54 CDT 2010
# HG changeset patch
# User Steve Losh <steve at stevelosh.com>
# Date 1272753580 14400
# Node ID 62c37bbaa8c651b2a220e320e1e7260b867b8a15
# Parent c2601c2163333a2f8913efc95e83f74dc0e912ad
cmdutil: warn when trying to copy/rename -A to a nonexistent file (issue1822)
Currently running 'hg rename/copy --after foo.txt bar.typo' is a silent no-op.
This patch adds a warning. It also updates the copy and rename tests.
No actual functionality is changed.
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -389,20 +389,26 @@
# check for overwrites
exists = os.path.exists(target)
if not after and exists or after and state in 'mn':
if not opts['force']:
ui.warn(_('%s: not overwriting - file exists\n') %
reltarget)
return
if after:
if not exists:
+ if rename:
+ ui.warn(_('%s: not recording move - %s does not exist\n') %
+ (relsrc, reltarget))
+ else:
+ ui.warn(_('%s: not recording copy - %s does not exist\n') %
+ (relsrc, reltarget))
return
elif not dryrun:
try:
if exists:
os.unlink(target)
targetdir = os.path.dirname(target) or '.'
if not os.path.isdir(targetdir):
os.makedirs(targetdir)
util.copyfile(src, target)
except IOError, inst:
diff --git a/tests/test-copy2 b/tests/test-copy2
--- a/tests/test-copy2
+++ b/tests/test-copy2
@@ -12,20 +12,23 @@
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
+echo "# copy --after to a nonexistent target filename"
+hg cp -A foo dummy
+
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
echo "# shouldn't show copy"
hg commit -m2
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
@@ -4,20 +4,22 @@
? foo
# dry-run; print a warning that this is not a real copy; foo is added
foo has not been committed yet, so no copy data will be stored for bar.
A foo
# should print a warning that this is not a real copy; bar is added
foo has not been committed yet, so no copy data will be stored for bar.
A bar
# should print a warning that this is not a real copy; foo is added
bar has not been committed yet, so no copy data will be stored for foo.
A foo
+# copy --after to a nonexistant target filename
+foo: not recording copy - dummy does not exist
# dry-run; should show that foo is clean
C foo
# should show copy
A bar
foo
# shouldn't show copy
# should match
rev offset length base linkrev nodeid p1 p2
0 0 5 0 0 2ed2a3912a0b 000000000000 000000000000
bar renamed from foo:2ed2a3912a0b24502043eae84ee4b279c18b90dd
diff --git a/tests/test-rename b/tests/test-rename
--- a/tests/test-rename
+++ b/tests/test-rename
@@ -16,20 +16,23 @@
hg update -C
rm d2/c
echo "# rename --after a single file"
mv d1/d11/a1 d2/c
hg rename --after d1/d11/a1 d2/c
hg status -C
hg update -C
rm d2/c
+echo "# rename --after a single file to a nonexistent target filename"
+hg rename --after d1/a dummy
+
echo "# move a single file to an existing directory"
hg rename d1/d11/a1 d2
hg status -C
hg update -C
rm d2/a1
echo "# move --after a single file to an existing directory"
mv d1/d11/a1 d2
hg rename --after d1/d11/a1 d2
hg status -C
diff --git a/tests/test-rename.out b/tests/test-rename.out
--- a/tests/test-rename.out
+++ b/tests/test-rename.out
@@ -1,20 +1,22 @@
# rename a single file
A d2/c
d1/d11/a1
R d1/d11/a1
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
# rename --after a single file
A d2/c
d1/d11/a1
R d1/d11/a1
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+# rename --after a single file to a nonexistant target filename
+d1/a: not recording move - dummy does not exist
# move a single file to an existing directory
A d2/a1
d1/d11/a1
R d1/d11/a1
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
# move --after a single file to an existing directory
A d2/a1
d1/d11/a1
R d1/d11/a1
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
@@ -163,20 +165,22 @@
d1/b
A d2/d21/ba
d1/ba
R d1/a
R d1/b
R d1/ba
R d1/d11/a1
4 files updated, 0 files merged, 0 files removed, 0 files unresolved
# move --after some files under d1 to d2/d21 (glob)
moving d1/a to d2/d21/a
+d1/b: not recording move - d2/d21/b does not exist
+d1/ba: not recording move - d2/d21/ba does not exist
moving d1/d11/a1 to d2/d21/a1
A d2/d21/a
d1/a
A d2/d21/a1
d1/d11/a1
R d1/a
R d1/d11/a1
2 files updated, 0 files merged, 0 files removed, 0 files unresolved
# move every file under d1 starting with an 'a' to d2/d21 (regexp)
moving d1/a to d2/d21/a
More information about the Mercurial-devel
mailing list