diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py --- a/mercurial/dirstate.py +++ b/mercurial/dirstate.py @@ -506,7 +506,7 @@ class dirstate(object): if files[i] < subpath: i += 1 continue - while files and files[i].startswith(subpath): + while i < len(files) and files[i].startswith(subpath): del files[i] j += 1 diff --git a/tests/test-subrepo-recursion.t b/tests/test-subrepo-recursion.t --- a/tests/test-subrepo-recursion.t +++ b/tests/test-subrepo-recursion.t @@ -346,3 +346,15 @@ Test missing subrepo: $ rm -r foo $ hg status -S warning: error "unknown revision '65903cebad86f1a84bd4f1134f62fa7dcb7a1c98'" in subrepository "foo" + +Issue2619: IndexError: list index out of range on hg add with subrepos +The subrepo must sorts after the explicit filename. + + $ cd .. + $ hg init test + $ cd test + $ hg init x + $ echo "x = x" >> .hgsub + $ hg add .hgsub + $ touch a x/a + $ hg add a x/a