diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py --- a/mercurial/subrepo.py +++ b/mercurial/subrepo.py @@ -1530,10 +1530,17 @@ class gitsubrepo(abstractsubrepo): (modified, added, removed, deleted, unknown, ignored, clean) = self.status(None) + tracked = set() + # dirstates 'amn' warn, 'r' is added again + for l in (modified, added, deleted, clean): + tracked.update(l) + # Unknown files not of interest will be rejected by the matcher files = unknown files.extend(match.files()) + rejected = [] + files = [f for f in sorted(set(files)) if match(f)] for f in files: exact = match.exact(f) @@ -1542,9 +1549,18 @@ class gitsubrepo(abstractsubrepo): command.append("-f") #should be added, even if ignored if ui.verbose or not exact: ui.status(_('adding %s\n') % match.rel(f)) + + if f in tracked: # hg prints 'adding' even if already tracked + if exact: + rejected.append(f) + continue if not opts.get('dry_run'): self._gitcommand(command + [f]) - return [] + + for f in rejected: + ui.warn(_("%s already tracked!\n") % match.abs(f)) + + return rejected @annotatesubrepoerror def remove(self): diff --git a/tests/test-subrepo-git.t b/tests/test-subrepo-git.t --- a/tests/test-subrepo-git.t +++ b/tests/test-subrepo-git.t @@ -974,7 +974,26 @@ correctly do a dry run ? s/cpp.cpp ? s/foobar.orig -currently no error given when adding an already tracked file +error given when adding an already tracked file $ hg add s/.gitignore + s/.gitignore already tracked! + [1] + +removed files can be re-added + $ hg ci --subrepos -m 'snake' + committing subrepository s + $ cd s + $ git rm snake.python + rm 'snake.python' + $ touch snake.python + $ cd .. + $ hg add s/snake.python + $ hg status -S + M s/snake.python + ? .hgignore + ? s/barfoo + ? s/c.c + ? s/cpp.cpp + ? s/foobar.orig $ cd ..