Status check is back in to prevent extraneous commit attempts; test added as well.

pull/55/head
Dave Musicant / thinkpad 6 years ago
parent 26d7fb354c
commit e493af3336

@ -276,11 +276,14 @@ eval $INCOMMAND | while read -r line; do
fi
cd "$TARGETDIR" # CD into right dir
"$GIT" add $GIT_ADD_ARGS # add file(s) to index
"$GIT" commit $GIT_COMMIT_ARGS -m"$FORMATTED_COMMITMSG" # construct commit message and commit
STATUS=$($GIT status -s)
if [ -n "$STATUS" ]; then # only commit if status shows tracked changes.
"$GIT" add $GIT_ADD_ARGS # add file(s) to index
"$GIT" commit $GIT_COMMIT_ARGS -m"$FORMATTED_COMMITMSG" # construct commit message and commit
if [ -n "$PUSH_CMD" ]; then
eval $PUSH_CMD;
if [ -n "$PUSH_CMD" ]; then
eval $PUSH_CMD;
fi
fi
) & # and send into background

@ -19,7 +19,6 @@ setup() {
}
@test "syncing correctly" {
# Start up gitwatch and see if commit and push happen automatically
# after waiting two seconds
${BATS_TEST_DIRNAME}/gitwatch.sh -r origin "$testdir/local/remote" 3>- &
@ -84,9 +83,8 @@ setup() {
@test "commit log messages working" {
# Start up gitwatch with logging, see if works
${BATS_TEST_DIRNAME}/gitwatch.sh -l 10 "$testdir/local/remote" 3>- &
${BATS_TEST_DIRNAME}/gitwatch.sh -l 10 "$testdir/local/remote" 3>&- &
GITWATCH_PID=$!
# Keeps kill message from printing to screen
@ -110,11 +108,40 @@ setup() {
# Check commit log that the diff is in there
run git log -1 --oneline
echo "# Output is $output" >&3
[[ $output == *"file1.txt"* ]]
}
@test "commit only when git status change" {
# Start up gitwatch and capture its output
${BATS_TEST_DIRNAME}/gitwatch.sh "$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
# 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 5
# Touch the file, but no change
touch file1.txt
sleep 5
run bash -c "grep \"nothing to commit\" \"$testdir/output.txt\" | wc -l"
[[ $output == "0" ]]
}
teardown() {
# Remove testing directories
cd /tmp

Loading…
Cancel
Save