diff options
author | André Erdmann <dywi@mailerd.de> | 2013-09-04 15:13:30 +0200 |
---|---|---|
committer | André Erdmann <dywi@mailerd.de> | 2013-09-04 15:13:30 +0200 |
commit | e5b7893c8af1ab5873761e55d7e21b41ba0ff56c (patch) | |
tree | 7e480b4a3c9187dce1b85f06dd7e1a608b9c3f51 /files | |
parent | config/: add hookrc file, files/shlib: itertools (diff) | |
download | R_overlay-e5b7893c8af1ab5873761e55d7e21b41ba0ff56c.tar.gz R_overlay-e5b7893c8af1ab5873761e55d7e21b41ba0ff56c.tar.bz2 R_overlay-e5b7893c8af1ab5873761e55d7e21b41ba0ff56c.zip |
files/hooks: git-push (experimental/todo)
Diffstat (limited to 'files')
-rw-r--r-- | files/hooks/git-push.sh | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/files/hooks/git-push.sh b/files/hooks/git-push.sh new file mode 100644 index 0000000..2dbb73e --- /dev/null +++ b/files/hooks/git-push.sh @@ -0,0 +1,69 @@ +#!/bin/sh +# -*- coding: utf-8 -*- +# roverlay hook that pushes the git history to a remote +# +# It's expected that git-commit-overlay is run before this hook. +# +set -u + +## load core functions +. "${FUNCTIONS?}" || exit +#dont_run_as_root + +# using line_iterator() from itertools +$lf itertools + + +## functions + +# void git_push_to_remote ( +# remote, *refspec, **__GIT_PUSH_SUCCESS!, **GIT_PUSH_ARGS +# ) +# +# Runs "git push" for the given remote and sets __GIT_PUSH_SUCCESS to 'n' +# if errors occured. +# +git_push_to_remote() { + if run_command_logged echo ${GIT} push ${GIT_PUSH_ARGS-} "$@"; then + veinfo "successfully pushed changes to ${1}" + else + __GIT_PUSH_SUCCESS=n + eerror "could not push changes to ${1}" + fi + return 0 +} + +# int git_push_to_remotes ( **GIT_REMOTES, **GIT_DEFAULT_REMOTE ) +# +# Calls git_push_to_remote() for each remote in GIT_REMOTES. +# Returns EX_GIT_PUSH_ERR if pushing failed for at least one remote, +# else 0. +# +git_push_to_remotes() { + [ -n "${GIT_REMOTES-}" ] || \ + local GIT_REMOTES="${GIT_DEFAULT_REMOTE:-origin} master" + # or "<remote> :" + + local __GIT_PUSH_SUCCESS=y + + F_ITER=git_push_to_remote \ + F_ITER_ON_ERROR=return \ + ITER_SKIP_EMTY=y \ + ITER_UNPACK_ITEM=y \ + line_iterator "${GIT_REMOTES}" + + if [ "${__GIT_PUSH_SUCCESS}" = "y" ]; then + return 0 + else + return ${EX_GIT_PUSH_ERR} + fi +} + + +## main + +if yesno "${NOSYNC?}"; then + einfo "sync is disabled - not pushing anything." +else + git_push_to_remotes +fi |