Updated feature for notify ignore

notifyignore v0.2
Dave Musicant (home machine) 6 months ago
parent 7e0b027cfc
commit 45c629ce6b

@ -51,7 +51,7 @@ shelp() {
echo ""
echo "Usage:"
echo "${0##*/} [-s <secs>] [-d <fmt>] [-r <remote> [-b <branch>]]"
echo " [-m <msg>] [-l|-L <lines>] [-M] <target>"
echo " [-m <msg>] [-l|-L <lines>] [-x <pattern>] [-M] <target>"
echo ""
echo "Where <target> is the file or folder which should be watched. The target needs"
echo "to be in a Git repository, or in the case of a folder, it may also be the top"
@ -91,6 +91,7 @@ shelp() {
echo " (useful when using inotify-win, e.g. -e modify,delete,move)"
echo " (currently ignored on Mac, which only uses default values)"
echo " -M Prevent commits when there is an ongoing merge in the repo"
echo " -x <pattern> Pattern to exclude from inotifywait"
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"
@ -132,7 +133,7 @@ is_merging () {
###############################################################################
while getopts b:d:h:g:L:l:m:p:r:s:e:M option; do # Process command line options
while getopts b:d:h:g:L:l:m:p:r:s:e:x:M option; do # Process command line options
case "${option}" in
b) BRANCH=${OPTARG} ;;
d) DATE_FMT=${OPTARG} ;;
@ -150,6 +151,7 @@ while getopts b:d:h:g:L:l:m:p:r:s:e:M option; do # Process command line options
M) SKIP_IF_MERGING=1 ;;
p | r) REMOTE=${OPTARG} ;;
s) SLEEP_TIME=${OPTARG} ;;
x) EXCLUDE_PATTERN=${OPTARG} ;;
e) EVENTS=${OPTARG} ;;
*)
stderr "Error: Option '${option}' does not exist."
@ -221,12 +223,19 @@ 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
if [ -z $EXCLUDE_PATTERN ]; then
EXCLUDE_OPTS="'(\.git/|\.git$)'"
else
EXCLUDE_OPTS="'(\.git/|\.git$|$EXCLUDE_PATTERN)'"
fi
# construct inotifywait-commandline
if [ "$(uname)" != "Darwin" ]; then
INW_ARGS=("-qmr" "-e" "$EVENTS" "--exclude" "'(\.git/|\.git$)'" "\"$TARGETDIR\"")
INW_ARGS=("-qmr" "-e" "$EVENTS" "--exclude" $EXCLUDE_OPTS "\"$TARGETDIR\"")
else
# still need to fix EVENTS since it wants them listed one-by-one
INW_ARGS=("--recursive" "$EVENTS" "-E" "--exclude" "'(\.git/|\.git$)'" "\"$TARGETDIR\"")
INW_ARGS=("--recursive" "$EVENTS" "-E" "--exclude" $EXCLUDE_OPTS "\"$TARGETDIR\"")
fi
GIT_ADD_ARGS="--all ." # add "." (CWD) recursively to index
GIT_COMMIT_ARGS="" # add -a switch to "commit" call just to be sure

@ -0,0 +1,55 @@
#!/usr/bin/env bats
# This is a testscript using the bats testing framework:
# https://github.com/sstephenson/bats
# To run it, at a command prompt:
# bats testscript.bats
load startup-shutdown
# Test for exclude from notifications. Verify that a subdirectory is ignored from notification.
function notify_ignore { #@test
# Start up gitwatch and capture its output
${BATS_TEST_DIRNAME}/../gitwatch.sh -x test_subdir "$testdir/local/remote" > "$testdir/output.txt" 3>&- &
GITWATCH_PID=$!
# Keeps kill message from printing to screen
disown
# Create a file, verify that it hasn't been added yet, then commit
cd remote
mkdir test_subdir
# According to inotify documentation, a race condition results if you write
# to directory too soon after it has been created; hence, a short wait.
sleep 1
echo "line1" >> file1.txt
# Wait a bit for inotify to figure out the file has changed, and do its add,
# and commit
sleep $WAITTIME
# Add second file that we plan to ignore
cd test_subdir
echo "line2" >> file2.txt
# Wait a bit for inotify to figure out the file has changed, and do its add,
# and commit
sleep $WAITTIME
cat "$testdir/output.txt"
run git log --name-status --oneline
echo $output
# Look for files in log: file1 should be there, file2 should not be
run grep "file1.txt" $testdir/output.txt
[ $status -eq 0 ]
run grep "file2.txt" $testdir/output.txt
[ $status -ne 0 ]
}

@ -29,6 +29,8 @@ teardown() {
kill -9 %1
fg
killall inotifywait
# Also make sure to kill fswatch if on Mac
killall fswatch
# Make sure gitwatch script gets killed if script stopped background

Loading…
Cancel
Save