Skip to content

Commit

Permalink
fsmonitor: fix empty path in dirfilter
Browse files Browse the repository at this point in the history
## Summary

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) 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.

## Test Plan

Added Mercurial integration test
  • Loading branch information
skevy committed Apr 13, 2023
1 parent ee02876 commit 9d0ad76
Show file tree
Hide file tree
Showing 3 changed files with 33 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
15 changes: 15 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,15 @@
#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
$ echo -e "/*\n!/foobar" > .gitignore
$ 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 9d0ad76

Please sign in to comment.