Skip to content

Commit

Permalink
Merge pull request #9 from jalkanen/master
Browse files Browse the repository at this point in the history
Support for attrib change watch (fixes #8)
  • Loading branch information
ivpusic committed Feb 3, 2016
2 parents 429b4f6 + 0c5ffef commit f6a3781
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Flags:
-s, --suffixes=SUFFIXES
File suffixes to watch.
-c, --config=CONFIG JSON configuration location
--attrib Also listen to changes to file attributes.
--version Show application version.
```

Expand All @@ -54,7 +55,8 @@ Create json file with content, with name for example conf.json
{
"ignore": ["some/path/to/ignore1", "some/path/to/ignore2"],
"args": ["dev", "test"],
"suffixes": [".go", ".html", ".tpl"]
"suffixes": [".go", ".html", ".tpl"],
"attrib": true
}
```
and then
Expand Down Expand Up @@ -100,5 +102,15 @@ You can use environment variables inside your configurations.
}
```

#### Use with Vagrant

If you are using Vagrant as your development environment, the edited changes do not fire the notify events on the guest side - meaning that rerun cannot detect the changes. However, if you install the vagrant-notify-forwarder plugin from https://github.com/mhallin/vagrant-notify-forwarder, you can make rerun work together with it:

vagrant plugin install vagrant-notify-forwarder

Then, watch the files with

rerun --attrib -c conf.json

# License
MIT
4 changes: 4 additions & 0 deletions conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ var (
args = kingpin.Flag("args", "Application arguments.").Default("").Short('a').String()
suffixes = kingpin.Flag("suffixes", "File suffixes to watch.").Short('s').String()
confPath = kingpin.Flag("config", "JSON configuration location").Short('c').String()
attrib = kingpin.Flag("attrib", "Also watch attribute changes").Bool()
)

type config struct {
Ignore []string
Args []string
Suffixes []string
Attrib bool
build string
}

Expand Down Expand Up @@ -92,5 +94,7 @@ func loadConfiguration() (*config, error) {
conf.Ignore = parseGlobs(conf.Ignore)
conf.Ignore = convertAbsolutes(conf.Ignore)

conf.Attrib = *attrib

return conf, nil
}
3 changes: 3 additions & 0 deletions conf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func TestParseConfWithCliArgs(t *testing.T) {
*ignore = "path1,path2"
*args = "arg1,arg2"
*suffixes = ".go,.html"
*attrib = true

cnf, err := loadConfiguration()
assert.Nil(t, err, "Error should not happen if file is ok")
Expand All @@ -35,4 +36,6 @@ func TestParseConfWithCliArgs(t *testing.T) {
assert.True(t, contains([]string{pathPrefix + "/path1", pathPrefix + "/path2"}, cnf.Ignore[1]))
AssertArraysEq(t, []string{"arg1", "arg2"}, cnf.Args)
AssertArraysEq(t, []string{".go", ".html"}, cnf.Suffixes)

assert.True(t, cnf.Attrib)
}
2 changes: 1 addition & 1 deletion watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (w *watcher) isEventImportant(ev fsnotify.Event) bool {
return false
}

importantEvent := ev.Op == fsnotify.Write || ev.Op == fsnotify.Rename || ev.Op == fsnotify.Remove
importantEvent := ev.Op == fsnotify.Write || ev.Op == fsnotify.Rename || ev.Op == fsnotify.Remove || (w.pm.conf.Attrib && ev.Op == fsnotify.Chmod)
if !importantEvent {
return false
}
Expand Down
9 changes: 9 additions & 0 deletions watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ func TestIsFileImportant(t *testing.T) {
event = fsnotify.Event{"some/file.c", fsnotify.Write}
assert.False(t, watcher.isEventImportant(event))

// Test attrib event
event = fsnotify.Event{"some/file.go", fsnotify.Chmod}
assert.False(t, watcher.isEventImportant(event))

// Test attrib event in case settings are different
pm.conf.Attrib = true
event = fsnotify.Event{"some/file.go", fsnotify.Chmod}
assert.True(t, watcher.isEventImportant(event))

// all ok
event = fsnotify.Event{"some/file.go", fsnotify.Write}
assert.True(t, watcher.isEventImportant(event))
Expand Down

0 comments on commit f6a3781

Please sign in to comment.