--- a/mercurial/commands.py Mon Dec 24 01:50:07 2007 +0100
+++ b/mercurial/commands.py Mon Dec 24 12:14:43 2007 +0100
@@ -26,17 +26,23 @@
If no names are given, add all files in the repository.
"""
+ rejected = None
+ exacts = {}
names = []
- for src, abs, rel, exact in cmdutil.walk(repo, pats, opts):
+ for src, abs, rel, exact in cmdutil.walk(repo, pats, opts,
+ badmatch=util.always):
if exact:
if ui.verbose:
ui.status(_('adding %s\n') % rel)
names.append(abs)
+ exacts[abs] = 1
elif abs not in repo.dirstate:
ui.status(_('adding %s\n') % rel)
names.append(abs)
if not opts.get('dry_run'):
- repo.add(names)
+ rejected = repo.add(names)
+ rejected = [p for p in rejected if p in exacts]
+ return rejected and 1 or 0
def addremove(ui, repo, *pats, **opts):
"""add all new files, delete all missing files
--- a/mercurial/localrepo.py Mon Dec 24 01:50:07 2007 +0100
+++ b/mercurial/localrepo.py Mon Dec 24 12:14:43 2007 +0100
@@ -1010,12 +1010,14 @@
def add(self, list):
wlock = self.wlock()
try:
+ rejected = []
for f in list:
p = self.wjoin(f)
try:
st = os.lstat(p)
except:
self.ui.warn(_("%s does not exist!\n") % f)
+ rejected.append(f)
continue
if st.st_size > 10000000:
self.ui.warn(_("%s: files over 10MB may cause memory and"
@@ -1025,12 +1027,14 @@
if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)):
self.ui.warn(_("%s not added: only files and symlinks "
"supported currently\n") % f)
+ rejected.append(p)
elif self.dirstate[f] in 'amn':
self.ui.warn(_("%s already tracked!\n") % f)
elif self.dirstate[f] == 'r':
self.dirstate.normallookup(f)
else:
self.dirstate.add(f)
+ return rejected
finally:
del wlock
--- a/tests/test-add Mon Dec 24 01:50:07 2007 +0100
+++ b/tests/test-add Mon Dec 24 12:14:43 2007 +0100
@@ -11,7 +11,7 @@
echo b > b
hg add -n b
hg st
-hg add b
+hg add b || echo "failed to add b"
hg st
echo % should fail
hg add b
@@ -40,3 +40,9 @@
echo a > a
hg add a
hg st
+
+hg add c && echo "unexpected addition of missing file"
+echo c > c
+hg add d c && echo "unexpected addition of missing file"
+hg st
+
--- a/tests/test-add.out Mon Dec 24 01:50:07 2007 +0100
+++ b/tests/test-add.out Mon Dec 24 12:14:43 2007 +0100
@@ -27,3 +27,7 @@
% issue683
R a
M a
+c does not exist!
+d does not exist!
+M a
+A c
--- a/tests/test-dispatch.py.out Mon Dec 24 01:50:07 2007 +0100
+++ b/tests/test-dispatch.py.out Mon Dec 24 12:14:43 2007 +0100
@@ -1,7 +1,7 @@
running: init test1
result: None
running: add foo
-result: None
+result: 0
running: commit -m commit1 -d 2000-01-01 foo
result: None
running: commit -m commit2 -d 2000-01-02 foo
--- a/tests/test-notfound.out Mon Dec 24 01:50:07 2007 +0100
+++ b/tests/test-notfound.out Mon Dec 24 12:14:43 2007 +0100
@@ -2,5 +2,5 @@
found: No such file or directory
not: No such file or directory
Is there an error message when trying to add non-existing files?
-found: No such file or directory
-not: No such file or directory
+found does not exist!
+not does not exist!