Skip to content

Commit

Permalink
fsmonitor: fix empty path in dirfilter (#601)
Browse files Browse the repository at this point in the history
Summary:
Fixes the bug discussed in Discord here: https://discord.com/channels/1042527964224557107/1042527965256364157/1095764831480590467

Running the ignore matcher on an empty path produces incorrect results. In the rust implementation, this isn't an issue, because there are directory matchers that run on the directory result. In the Python treestate bindings, we don't have that functionality, so it returns an empty string.

This makes this logic match the code in `dirstate.py` ([line ~925](https://github.com/facebook/sapling/blob/main/eden/scm/edenscm/dirstate.py#L925-L926)) where we check for path being an empty string.

This fixes `sl status` (and related functionality) when fsmonitor is enabled and there's a complex gitignore file that ignores files in the root directory.

Pull Request resolved: #601

Test Plan: Added Mercurial integration test and manually tested locally

Reviewed By: quark-zju

Differential Revision: D44961756

Pulled By: zzl0

fbshipit-source-id: 57dd0d052ceeb184694c6f3b1a71ac53bf0e1028
  • Loading branch information
skevy authored and facebook-github-bot committed Apr 13, 2023
1 parent b8d2773 commit 54300ad
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions eden/scm/edenscm/ext/fsmonitor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,8 @@ def _innerwalk(self, match, event, span):
ignorevisitdir = self.dirstate._ignore.visitdir

def dirfilter(path):
if path == "":
return False
result = ignorevisitdir(path.rstrip("/"))
return result == "all"

Expand Down
16 changes: 16 additions & 0 deletions eden/scm/tests/test-gitignore.t
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,19 @@
? exp/.gitignore
? exp/i.tmp
? x.pyc

# Test exclusion patterns

$ cat > .gitignore << 'EOF'
> /*
> !/build
> EOF

$ rm -rf build/
$ mkdir build
$ touch build/libfoo.so t.tmp Makefile

$ hg status
? build/libfoo.so
$ hg status
? build/libfoo.so
20 changes: 20 additions & 0 deletions eden/scm/tests/test-status-root-ignored-py.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#debugruntest-compatible
#require fsmonitor

$ configure modernclient
$ setconfig status.use-rust=False workingcopy.ruststatus=False
$ newrepo

Ensure that, when files in the root are ignored and there is an exclusion, that hg status returns the correct value

$ cat > .gitignore << 'EOF'
> /*
> !/foobar
> EOF
$ hg status
$ mkdir foobar
$ touch root-file foobar/foo # adds files to root and to foobar
$ hg status
? foobar/foo
$ hg status # run it a second time to ensure that we didn't accidentally exclude the file
? foobar/foo

0 comments on commit 54300ad

Please sign in to comment.