make branch and remote configurable as environment
This commit is contained in:
parent
69f1d1eb56
commit
4b55ad420f
1 changed files with 11 additions and 4 deletions
|
@ -15,6 +15,8 @@
|
||||||
MYSHELLCONFIG_LOGDIR="./logs"
|
MYSHELLCONFIG_LOGDIR="./logs"
|
||||||
MYSHELLCONFIG_LOGFILE="${MYSHELLCONFIG_LOGDIR}/git.log"
|
MYSHELLCONFIG_LOGFILE="${MYSHELLCONFIG_LOGDIR}/git.log"
|
||||||
[ -d "${MYSHELLCONFIG_LOGDIR}" ] || mkdir -p "${MYSHELLCONFIG_LOGDIR}"
|
[ -d "${MYSHELLCONFIG_LOGDIR}" ] || mkdir -p "${MYSHELLCONFIG_LOGDIR}"
|
||||||
|
[ -z "${MYSHELLCONFIG_GIT_REMOTE_NAME:+x}" ] || export MYSHELLCONFIG_GIT_REMOTE_NAME=origin
|
||||||
|
[ -z "${MYSHELLCONFIG_GIT_BRANCH:+x}" ] || export MYSHELLCONFIG_GIT_BRANCH=master
|
||||||
|
|
||||||
cat << EOF >> "${MYSHELLCONFIG_LOGFILE}"
|
cat << EOF >> "${MYSHELLCONFIG_LOGFILE}"
|
||||||
+-----BEGINN $(date) -------------------------------+
|
+-----BEGINN $(date) -------------------------------+
|
||||||
|
@ -23,22 +25,26 @@ EOF
|
||||||
case $1 in
|
case $1 in
|
||||||
-h)
|
-h)
|
||||||
# Headless repo local
|
# Headless repo local
|
||||||
PRE="origin/"
|
PRE="${MYSHELLCONFIG_GIT_REMOTE_NAME}"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
PRE=""
|
PRE=""
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
$SGIT fetch origin -p 2>>"${MYSHELLCONFIG_LOGFILE}"|| { echo fetch failed; exit 1; }
|
# If TAG is set, checkout is always headless.
|
||||||
|
[ -z "${MYSHELLCONFIG_GIT_TAG:+x}" ] || { export MYSHELLCONFIG_GIT_BRANCH=${MYSHELLCONFIG_GIT_TAG}; export PRE=""; }
|
||||||
|
|
||||||
|
|
||||||
|
$SGIT fetch ${MYSHELLCONFIG_GIT_REMOTE_NAME} -p 2>>"${MYSHELLCONFIG_LOGFILE}"|| { echo fetch failed; exit 1; }
|
||||||
|
|
||||||
if $SGIT diff-index --ignore-submodules --exit-code HEAD -- >> "${MYSHELLCONFIG_LOGFILE}" ; then
|
if $SGIT diff-index --ignore-submodules --exit-code HEAD -- >> "${MYSHELLCONFIG_LOGFILE}" ; then
|
||||||
cat << EOF >> "${MYSHELLCONFIG_LOGFILE}"
|
cat << EOF >> "${MYSHELLCONFIG_LOGFILE}"
|
||||||
Check for local changes:
|
Check for local changes:
|
||||||
no changes in local repo
|
no changes in local repo
|
||||||
$SGIT checkout repo ${PRE}master
|
$SGIT checkout repo ${PRE}${PRE:+/}${MYSHELLCONFIG_GIT_BRANCH}
|
||||||
EOF
|
EOF
|
||||||
#echo "checkout origin/master as detached HEAD"
|
#echo "checkout origin/master as detached HEAD"
|
||||||
$SGIT checkout ${PRE}master 1>>"${MYSHELLCONFIG_LOGFILE}" 2>>"${MYSHELLCONFIG_LOGFILE}"|| exit 2
|
$SGIT checkout ${PRE}${PRE:+/}${MYSHELLCONFIG_GIT_BRANCH} 1>>"${MYSHELLCONFIG_LOGFILE}" 2>>"${MYSHELLCONFIG_LOGFILE}"|| exit 2
|
||||||
$SGIT merge FETCH_HEAD 1>>"${MYSHELLCONFIG_LOGFILE}" 2>>"${MYSHELLCONFIG_LOGFILE}"|| exit 3
|
$SGIT merge FETCH_HEAD 1>>"${MYSHELLCONFIG_LOGFILE}" 2>>"${MYSHELLCONFIG_LOGFILE}"|| exit 3
|
||||||
else
|
else
|
||||||
cat << EOF >> "${MYSHELLCONFIG_LOGFILE}"
|
cat << EOF >> "${MYSHELLCONFIG_LOGFILE}"
|
||||||
|
@ -83,6 +89,7 @@ rc=0
|
||||||
#$SGIT submodule update --recursive --remote --merge 1>>"${MYSHELLCONFIG_LOGFILE}" 2>&1|| { echo update submodules failed; exit 1; }
|
#$SGIT submodule update --recursive --remote --merge 1>>"${MYSHELLCONFIG_LOGFILE}" 2>&1|| { echo update submodules failed; exit 1; }
|
||||||
|
|
||||||
#echo "update submodules" >&2
|
#echo "update submodules" >&2
|
||||||
|
# Submodules always have origin and master as repo and branch to track
|
||||||
$SGIT submodule init 1>>"${MYSHELLCONFIG_LOGFILE}" 2>&1|| { echo update submodules failed on ini; rc=5; }
|
$SGIT submodule init 1>>"${MYSHELLCONFIG_LOGFILE}" 2>&1|| { echo update submodules failed on ini; rc=5; }
|
||||||
$SGIT submodule sync 1>>"${MYSHELLCONFIG_LOGFILE}" 2>&1|| { echo sync submodules failed on sync; rc=6; }
|
$SGIT submodule sync 1>>"${MYSHELLCONFIG_LOGFILE}" 2>&1|| { echo sync submodules failed on sync; rc=6; }
|
||||||
$SGIT submodule foreach "git checkout master" 1>>"${MYSHELLCONFIG_LOGFILE}" 2>&1|| { echo checkout master submodules failed on set upstream; rc=7; }
|
$SGIT submodule foreach "git checkout master" 1>>"${MYSHELLCONFIG_LOGFILE}" 2>&1|| { echo checkout master submodules failed on set upstream; rc=7; }
|
||||||
|
|
Loading…
Reference in a new issue