diff --git a/hgext/fbsparse.py b/hgext/fbsparse.py index 0331232ccc..19589b1ca3 100644 --- a/hgext/fbsparse.py +++ b/hgext/fbsparse.py @@ -9,7 +9,7 @@ """ from mercurial import util, cmdutil, extensions, context, dirstate, commands -from mercurial import localrepo, error, hg, pathutil, registrar, patch +from mercurial import localrepo, error, hg, pathutil, registrar, patch, pycompat from mercurial import match as matchmod from mercurial import merge as mergemod from mercurial.node import nullid @@ -1202,26 +1202,26 @@ def _cwdlist(repo): """ ctx = repo['.'] mf = ctx.manifest() - cwd = util.normpath(os.getcwd()) # Get the root of the repo so that we remove the content of # the root from the current working directory root = repo.root - if cwd.startswith(root): - cwd = cwd[len(root):] - else: - raise error.Abort(_("the current working directory should begin " + - "with the root %s") % root) + cwd = util.normpath(pycompat.getcwd()) + cwd = os.path.relpath(cwd, root) + cwd = '' if cwd == os.curdir else cwd + pycompat.ossep + if cwd.startswith(os.pardir + pycompat.ossep): + raise error.Abort( + _("the current working directory should begin " + "with the root %s") % root) - cwd = cwd.strip("/") sparsematch = repo.sparsematch(ctx.rev()) checkedoutentries = set() allentries = set() - cwdlength = len(cwd) + 1 + cwdlength = len(cwd) + for filepath in mf: if filepath.startswith(cwd): - tail = filepath[cwdlength:] if cwdlength > 1 else filepath - entryname = tail.split('/', 1)[0] + entryname = filepath[cwdlength:].partition(pycompat.ossep)[0] allentries.add(entryname) if sparsematch(filepath): diff --git a/tests/test-check-code.t b/tests/test-check-code.t index 62e054d0a0..cad419ed5e 100644 --- a/tests/test-check-code.t +++ b/tests/test-check-code.t @@ -95,9 +95,6 @@ New errors are not allowed. Warnings are strongly discouraged. hgext/fastannotate/commands.py:43: > reldir = os.path.relpath(os.getcwd(), reporoot) use pycompat.getcwd instead (py3) - hgext/fbsparse.py:1205: - > cwd = util.normpath(os.getcwd()) - use pycompat.getcwd instead (py3) Skipping hgext/hgsql.py it has no-che?k-code (glob) Skipping hgext/hgsubversion/__init__.py it has no-che?k-code (glob) Skipping hgext/hgsubversion/compathacks.py it has no-che?k-code (glob) diff --git a/tests/test-fb-hgext-sparse.t b/tests/test-fb-hgext-sparse.t index 71b35da84d..8b386840aa 100644 --- a/tests/test-fb-hgext-sparse.t +++ b/tests/test-fb-hgext-sparse.t @@ -354,7 +354,20 @@ Test --cwd-list $ hg sparse --cwd-list - bar foo - $ cd .. + +Make sure to match whole directory names, not prefixes + + $ mkdir prefix prefixpostfix + $ touch prefix/correct prefixpostfix/incorrect + $ hg sparse -I prefix prefixpostfix + $ hg addremove . + adding prefix/correct + adding prefixpostfix/incorrect + $ hg ci -m 'subdirs' + $ cd prefix + $ hg sparse --cwd-list + correct + $ cd ../.. $ cd ..