-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgit-hook-run-parts
executable file
·41 lines (33 loc) · 1.1 KB
/
git-hook-run-parts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env bash
export YP_GIT_HOOK=true
export YP_GIT_HOOK_PATH=$1
export YP_GIT_HOOK_NAME=$(basename ${YP_GIT_HOOK_PATH})
shift
function on_exit() {
# shellcheck disable=SC2181
[[ "$?" != "0" ]] || return 0
echo_err "${YP_GIT_HOOK_NAME} hook failed."
[[ "${YP_GIT_HOOK_NAME}" != "pre-push" ]] || {
echo_indent
echo_info "If you want ignore the hook and push anyway, use 'git push --no-verify ...'."
}
}
trap on_exit EXIT
GIT_ROOT=$(git rev-parse --show-toplevel)
YP_DIR="${GIT_ROOT}/yplatform"
source ${YP_DIR}/sh/common.inc.sh
[[ "${YP_GIT_HOOK_NAME}" != "pre-push" ]] || {
GIT_MODIFIED_FILES="$(git diff --name-only)"
[[ -z "${GIT_MODIFIED_FILES}" ]] || {
echo_indent
echo_warn "The files/submodules below are modified and unstaged,"
echo_warn "so the push might fail because of unstaged changes, not related to actual commits."
echo_indent "${GIT_MODIFIED_FILES}"
echo_indent
}
}
${YP_DIR}/bin/linux-run-parts \
--verbose \
--stdin \
$(for ARG in "$@"; do echo "--arg" "${ARG}"; done) \
"${YP_GIT_HOOK_PATH}.d"