Merge pull request #55 from gitwatch/47-mac-darwin

Enabled OS X functionality with fswatch
pull/56/head
Dave Musicant 5 years ago committed by GitHub
commit 93a956ec35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,8 +1,18 @@
language: bash
before_install:
- sudo add-apt-repository ppa:duggan/bats --yes
- sudo apt-get update -qq
- sudo apt-get install -qq bats
- sudo apt-get install inotify-tools
os:
- linux
- osx
addons:
apt:
sources:
- sourceline: 'ppa:duggan/bats'
packages:
- bats
- inotify-tools
homebrew:
packages:
- fswatch
- coreutils # in order to get greadlink
- bats-core
script:
- bats tests

@ -18,7 +18,7 @@ do that for you if `/usr/local/bin` is in your `$PATH`. You may need to
invoke `install` with `sudo`.
```sh
$ git clone https://github.com/nevik/gitwatch.git
$ git clone https://github.com/gitwatch/gitwatch.git
$ cd gitwatch
$ [sudo] install -b gitwatch.sh /usr/local/bin/gitwatch
```
@ -30,7 +30,7 @@ running the command below. You may need to invoke `bpkg` with `sudo`
when using the `-g` flag.
```sh
$ [sudo] bpkg install -g nevik/gitwatch
$ [sudo] bpkg install -g gitwatch/gitwatch
```
## Requirements
@ -38,6 +38,15 @@ To run this script, you must have installed and globally available:
* `git` ( [git/git](https://github.com/git/git) | http://www.git-scm.com )
* `inotifywait` (part of **inotify-tools**: [rvoicilas/inotify-tools](https://github.com/rvoicilas/inotify-tools) )
### Notes for Mac
If running on OS X, you'll need to install the following Homebrew tools:
```sh
$ brew install fswatch
$ brew install coreutils
```
## What it does
When you start the script, it prepares some variables and checks if the file [a] or directory [b] given as input really exists.<br />
Then it goes into the main loop (which will run forever, until the script is forcefully stopped/killed), which will:
@ -80,4 +89,4 @@ Note that this method assumes you have Gitwatch installed in `/opt/gitwatch`
## Other Articles
### On the Gitwatch Wiki
* [How to install `gitwatch` as a Debian service with `supervisord`](https://github.com/nevik/gitwatch/wiki/gitwatch-as-a-service-on-Debian-with-supervisord)
* [How to install `gitwatch` as a Debian service with `supervisord`](https://github.com/gitwatch/gitwatch/wiki/gitwatch-as-a-service-on-Debian-with-supervisord)

@ -1,4 +1,4 @@
#!/usr/bin/env bash
#fsw!/usr/bin/env bash
#
# gitwatch - watch file or directory and git commit all changes as they happen
#
@ -42,7 +42,6 @@ DATE_FMT="+%Y-%m-%d %H:%M:%S"
COMMITMSG="Scripted auto-commit on change (%d) by gitwatch.sh"
LISTCHANGES=-1
LISTCHANGES_COLOR="--color=always"
EVENTS="close_write,move,delete,create"
GIT_DIR=""
# Print a message about how to use this script
@ -89,6 +88,7 @@ shelp () {
echo " -e <events> Events passed to inotifywait to watch (defaults to "
echo " '$EVENTS')"
echo " (useful when using inotify-win, e.g. -e modify,delete,move)"
echo " (currently ignored on Mac, which only uses default values)"
echo ""
echo "As indicated, several conditions are only checked once at launch of the"
echo "script. You can make changes to the repo state and configurations even while"
@ -150,7 +150,23 @@ fi
# if custom bin names are given for git or inotifywait, use those; otherwise fall back to "git" and "inotifywait"
if [ -z "$GW_GIT_BIN" ]; then GIT="git"; else GIT="$GW_GIT_BIN"; fi
if [ -z "$GW_INW_BIN" ]; then INW="inotifywait"; else INW="$GW_INW_BIN"; fi
if [ -z "$GW_INW_BIN" ]; then
# if Mac, use fswatch
if [ "$(uname)" != "Darwin" ]; then
INW="inotifywait";
EVENTS="close_write,move,delete,create";
else
INW="fswatch";
# default events specified via a mask, see
# https://emcrisostomo.github.io/fswatch/doc/1.14.0/fswatch.html/Invoking-fswatch.html#Numeric-Event-Flags
# default of 414 = MovedTo + MovedFrom + Renamed + Removed + Updated + Created
# = 256 + 128+ 16 + 8 + 4 + 2
EVENTS="--event=414"
fi;
else
INW="$GW_INW_BIN";
fi
# Check availability of selected binaries and die if not met
for cmd in "$GIT" "$INW"; do
@ -166,16 +182,36 @@ trap "cleanup" EXIT # make sure the timeout is killed when exiting script
# Expand the path to the target to absolute path
IN=$(readlink -f "$1")
if [ "$(uname)" != "Darwin" ]; then
IN=$(readlink -f "$1")
else
IN=$(greadlink -f "$1")
fi;
if [ -d "$1" ]; then # if the target is a directory
TARGETDIR=$(sed -e "s/\/*$//" <<<"$IN") # dir to CD into before using git commands: trim trailing slash, if any
INCOMMAND="\"$INW\" -qmr -e \"$EVENTS\" --exclude \"\.git\" \"$TARGETDIR\"" # construct inotifywait-commandline
# construct inotifywait-commandline
if [ "$(uname)" != "Darwin" ]; then
INCOMMAND="\"$INW\" -qmr -e \"$EVENTS\" --exclude \"\.git\" \"$TARGETDIR\""
else
# still need to fix EVENTS since it wants them listed one-by-one
INCOMMAND="\"$INW\" --recursive \"$EVENTS\" --exclude \"\.git\" \"$TARGETDIR\""
fi;
GIT_ADD_ARGS="--all ." # add "." (CWD) recursively to index
GIT_COMMIT_ARGS="" # add -a switch to "commit" call just to be sure
elif [ -f "$1" ]; then # if the target is a single file
TARGETDIR=$(dirname "$IN") # dir to CD into before using git commands: extract from file name
INCOMMAND="\"$INW\" -qm -e \"$EVENTS\" \"$IN\"" # construct inotifywait-commandline
# construct inotifywait-commandline
if [ "$(uname)" != "Darwin" ]; then
INCOMMAND="\"$INW\" -qm -e \"$EVENTS\" \"$IN\""
else
INCOMMAND="\"$INW\" \"$EVENTS\" \"$IN\""
fi;
GIT_ADD_ARGS="$IN" # add only the selected file to index
GIT_COMMIT_ARGS="" # no need to add anything more to "commit" call
else

@ -32,8 +32,13 @@ load startup-shutdown
touch file1.txt
sleep $WAITTIME
run bash -c "grep \"nothing to commit\" \"$testdir/output.txt\" | wc -l"
[[ $output == "0" ]]
echo "hi there" > "$testdir/output.txt"
cat "$testdir/output.txt"
run git log -1 --oneline
echo $output
#run bash -c "grep \"nothing to commit\" $testdir/output.txt | wc -l"
run grep "nothing to commit" $testdir/output.txt
[ $status -ne 0 ]
}

Loading…
Cancel
Save