Skip to content

Commit

Permalink
Merge pull request #13 from ttd2089/feat/allow-running-without-gitignore
Browse files Browse the repository at this point in the history
feat: allow the app to run when git is not found
  • Loading branch information
tshowers-bt authored Jun 30, 2022
2 parents 7dd27a9 + 5866e5b commit 909f52e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion gitignore.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var GitIgnoreSupported = false

func initGitignore() {
if _, err := exec.LookPath("git"); err != nil {
logger.Printf("gitignore not supported: %v", err)
logger.Printf("gitignore not supported: %v\n", err)
} else {
GitIgnoreSupported = true
}
Expand Down
14 changes: 8 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ func main() {
// Runs the command and re-starts it on file changes.
func run(cmd string, args ...string) {

// TODO: support other filter options?
if !GitIgnoreSupported {
die("error: gitignore filter not supported")
filter := func(_ FsEvent) (bool, error) {
return false, nil
}

filter := func(event FsEvent) (bool, error) {
return GitIgnored(event.Path)
if GitIgnoreSupported {
logger.Printf("using .gitignore filter")
filter = func(event FsEvent) (bool, error) {
return GitIgnored(event.Path)
}
}

watcher, err := NewWatcher(filter)
Expand All @@ -96,7 +98,7 @@ func run(cmd string, args ...string) {

handle := func(e WatcherEvent) error {
if e.Error != nil {
logger.Printf("watcher error: %v", e.Error)
logger.Printf("watcher error: %v\n", e.Error)
return nil
}
if err = stopProcess(proc); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions main_nonwindows.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ func stopProcess(proc *exec.Cmd) error {
pid := proc.Process.Pid

if err := syscall.Kill(-pid, syscall.SIGINT); err != nil {
logger.Printf("failed to send SIGINT to %s: %s", path.Base(proc.Path), err.Error())
logger.Printf("failed to send SIGINT to %s: %s\n", path.Base(proc.Path), err.Error())
} else {
// If the sigint worked then give it a moment
time.Sleep(200 * time.Millisecond)
}

if err := syscall.Kill(-pid, syscall.SIGKILL); err != nil {
return fmt.Errorf("failed to kill %s: %s", path.Base(proc.Path), err.Error())
return fmt.Errorf("failed to kill %s: %s\n", path.Base(proc.Path), err.Error())
}

// This will error with 'signal: killed' or 'exit status 1' if we killed
Expand Down
4 changes: 2 additions & 2 deletions watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ func (w *watcherImpl) start() {
skip, err := w.filter(fsEvent)
if err != nil {
logger.Printf(
"watcher filter error: event=%v, error=%v", fsEvent, err)
"watcher filter error: event=%v, error=%v\n", fsEvent, err)
} else if skip {
logger.Printf("watcher filter: ignoring event %v", fsEvent)
logger.Printf("watcher filter: ignoring event %v\n", fsEvent)
break
}
w.events <- WatcherEvent{
Expand Down

0 comments on commit 909f52e

Please sign in to comment.