[PATCH] remove: properly set return code when warnings are issued
Brodie Rao
brodie at bitheap.org
Mon Aug 30 19:35:30 CDT 2010
# HG changeset patch
# User Brodie Rao <brodie at bitheap.org>
# Date 1283214445 14400
# Branch stable
# Node ID 91142314b384998289aa06e239b4c426e00adda3
# Parent ee601a6264e0e78caa36a43709494669214fccfe
remove: properly set return code when warnings are issued
This removes the warn() function in favor of issuing warnings directly
for each kind of file that Mercurial won't remove.
This also uses three separate translatable strings instead of using
string formatting to build the message. This should make it easier to
localize.
diff -r ee601a6264e0 -r 91142314b384 mercurial/commands.py
--- a/mercurial/commands.py Mon Aug 30 22:47:38 2010 +0200
+++ b/mercurial/commands.py Mon Aug 30 20:27:25 2010 -0400
@@ -2916,21 +2916,24 @@ def remove(ui, repo, *pats, **opts):
ui.warn(_('not removing %s: file is untracked\n') % m.rel(f))
ret = 1
- def warn(files, reason):
- for f in files:
- ui.warn(_('not removing %s: file %s (use -f to force removal)\n')
- % (m.rel(f), reason))
- ret = 1
-
if force:
remove, forget = modified + deleted + clean, added
elif after:
remove, forget = deleted, []
- warn(modified + added + clean, _('still exists'))
+ for f in modified + added + clean:
+ ui.warn(_('not removing %s: file still exists (use -f'
+ ' to force removal)\n') % m.rel(f))
+ ret = 1
else:
remove, forget = deleted + clean, []
- warn(modified, _('is modified'))
- warn(added, _('has been marked for add'))
+ for f in modified:
+ ui.warn(_('not removing %s: file is modified (use -f'
+ ' to force removal)\n') % m.rel(f))
+ ret = 1
+ for f in added:
+ ui.warn(_('not removing %s: file has been marked for add (use -f'
+ ' to force removal)\n') % m.rel(f))
+ ret = 1
for f in sorted(remove + forget):
if ui.verbose or not m.exact(f):
diff -r ee601a6264e0 -r 91142314b384 tests/test-remove
--- a/tests/test-remove Mon Aug 30 22:47:38 2010 +0200
+++ b/tests/test-remove Mon Aug 30 20:27:25 2010 -0400
@@ -2,6 +2,7 @@
remove() {
hg rm $@
+ RET=$?
hg st
# do not use ls -R, which recurses in .hg subdirs on Mac OS X 10.5
find . -name .hg -prune -o -type f -print | sort
@@ -14,6 +15,7 @@ echo a > foo
echo % file not managed
remove foo
+echo $RET
hg add foo
hg commit -m1
@@ -24,6 +26,7 @@ echo % 00 state added, options none
echo b > bar
hg add bar
remove bar
+echo $RET
echo % 01 state clean, options none
remove foo
@@ -31,6 +34,7 @@ remove foo
echo % 02 state modified, options none
echo b >> foo
remove foo
+echo $RET
echo % 03 state missing, options none
rm foo
@@ -57,6 +61,7 @@ echo % 20 state added, options -A
echo b > bar
hg add bar
remove -A bar
+echo $RET
echo % 21 state clean, options -A
remove -A foo
diff -r ee601a6264e0 -r 91142314b384 tests/test-remove.out
--- a/tests/test-remove.out Mon Aug 30 22:47:38 2010 +0200
+++ b/tests/test-remove.out Mon Aug 30 20:27:25 2010 -0400
@@ -1,10 +1,12 @@
% file not managed
not removing foo: file is untracked
+1
? foo
./foo
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
% 00 state added, options none
not removing bar: file has been marked for add (use -f to force removal)
+1
A bar
./bar
./foo
@@ -16,6 +18,7 @@ R foo
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
% 02 state modified, options none
not removing foo: file is modified (use -f to force removal)
+1
M foo
? bar
./bar
@@ -42,6 +45,7 @@ R foo
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
% 20 state added, options -A
not removing bar: file still exists (use -f to force removal)
+1
A bar
./bar
./foo
More information about the Mercurial-devel
mailing list