forever: .foreverignore file not working for sub directories with -w

Normal ignore rules don’t seem to work correctly with forever. I was trying to add my .git folder and was unable to get it working. I tried with the below file.

.git
.git/
.git/*

The first line is the only one that should be needed.

If you did a git pull and a file changed in the .git folder forever would restart.

info:   restaring script because /mnt/home/test/.git/FETCH_HEAD changed
warn: Forever detected script exited with code: null
warn: Forever restarting script for 1 time

About this issue

  • Original URL
  • State: closed
  • Created 12 years ago
  • Comments: 47 (6 by maintainers)

Commits related to this issue

Most upvoted comments

I love forever, and have used the CLI for many years in many projects. The developers deserve enormous credit.

Now, I’m using v0.15.3 and in my case, ignored subdirectories are being watched. This has been so for years, and I’ve come back to this thread a half dozen times over the past 4-5 years.

I think the following sums up the situation: (i) The maintainers seemed to regard the problem with the CLI as fixed before it worked the way the users above wanted. (ii) There’s no test in place that covers the way the users above want the CLI to work.

The following demonstrates the the CLI does not respect .foreverignore subdirectories, exactly as OP described (paste into terminal):

# Create a project directory.
cd ~ && mkdir foo-project

# Create project files.
echo "require('http').createServer(r => {}).listen(3000)" > foo-project/index.js
mkdir foo-project/foo
mkdir foo-project/foo/bar
echo "console.log('fizz');" > foo-project/foo/bar/index.js

# Add .foreverignore to tell forever to ignore foo.
echo "foo" > foo-project/.foreverignore

# Add a JSON conf file to tell forever to watch the project.
echo "{\"watch\":true,\"script\":\"index.js\"}" > foo-project/forever-conf.json

# Run the project.
cd foo-project && forever start forever-conf.json

$ forever list will show a running process. Now we’ll change a file that lives in foo/bar (paste into terminal):

cd ../
echo "console.log('buzz');" >> foo-project/foo/bar/index.js

The process should not have restarted, but the log file will indicate that it did so:

error: restarting script because add changed
error: Forever detected script was killed by signal: SIGKILL
error: Script restart attempt #1

If I’m doing something wrong here, please indicate how I should change what I’m doing; I’ll be grateful.

**/.git/** is working for me in .foreverignore with v0.11.1

It’s a bug in plugins/watch.js

watchFilter() calls minimatch this way:

minimatch(fileName, this.watchIgnorePatterns[key], { matchBase: this.watchDirectory })

But minimatch doesn’t use matchBase as a base path, it’s a boolean argument. So minimatch matches pattern against full file path.

You can workaround it for now, using

**/.git/**

But this should be fixed, surely.