# HG changeset patch # User Patrick Mezard # Date 2007-12-24 11:14:43 # Node ID 883d887c64082052602f057cee9c49b75438be2c # Parent ca7af19debea5d3543668317bbf3b400f9da8997 commands: add exits(1) if a specified file cannot be added (issue 891) diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -26,17 +26,23 @@ def add(ui, repo, *pats, **opts): 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 diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -1010,12 +1010,14 @@ class localrepository(repo.repository): 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 @@ class localrepository(repo.repository): 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 diff --git a/tests/test-add b/tests/test-add --- a/tests/test-add +++ b/tests/test-add @@ -11,7 +11,7 @@ hg st 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 @@ hg st 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 + diff --git a/tests/test-add.out b/tests/test-add.out --- a/tests/test-add.out +++ b/tests/test-add.out @@ -27,3 +27,7 @@ M a % issue683 R a M a +c does not exist! +d does not exist! +M a +A c diff --git a/tests/test-dispatch.py.out b/tests/test-dispatch.py.out --- a/tests/test-dispatch.py.out +++ b/tests/test-dispatch.py.out @@ -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 diff --git a/tests/test-notfound.out b/tests/test-notfound.out --- a/tests/test-notfound.out +++ b/tests/test-notfound.out @@ -2,5 +2,5 @@ Is there an error message when trying to 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!