Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 29 additions & 29 deletions git-repo-watcher
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,35 @@ print_usage() {
exit 1
}

# Executes user hooks
#
# $1 - Hook name
# $2-$4 - Hook arguments
hook() {
hook_name="$1"
shift
if [[ "$(type -t "$hook_name")" == "function" ]]; then
eval "$hook_name $*"
fi
}

# Pulls commit from remote git repository
#
# $1 - Git repository name
# $2 - Branch name
pull_change() {
git pull
exit_code=$?

commit_message=$(git log -1 --pretty=format:"%h | %an | %ad | %s")

if [[ $exit_code -eq 1 ]]; then
hook "pull_failed" "$1" "$2" "$commit_message"
else
hook "change_pulled" "$1" "$2" "$(printf '%q\n' "$commit_message")"
fi
}

while getopts ":d:i:h:o" options; do
case "${options}" in
d)
Expand Down Expand Up @@ -79,35 +108,6 @@ if [[ -z "$interval_in_seconds" ]]; then
interval_in_seconds="$default_interval_in_seconds"
fi

# Executes user hooks
#
# $1 - Hook name
# $2-$4 - Hook arguments
hook() {
hook_name="$1"
shift
if [[ "$(type -t "$hook_name")" == "function" ]]; then
eval "$hook_name $*"
fi
}

# Pulls commit from remote git repository
#
# $1 - Git repository name
# $2 - Branch name
pull_change() {
git pull
exit_code=$?

commit_message=$(git log -1 --pretty=format:"%h | %an | %ad | %s")

if [[ $exit_code -eq 1 ]]; then
hook "pull_failed" "$1" "$2" "$commit_message"
else
hook "change_pulled" "$1" "$2" "$(printf '%q\n' "$commit_message")"
fi
}

while true; do

cd "$git_repository_dir" || exit 1
Expand Down