Prepare room for different DVCS backends
This commit is contained in:
parent
e1b6a7b358
commit
3dd1343ec8
144
forgebuild.sh
144
forgebuild.sh
|
@ -68,6 +68,85 @@ help () {
|
|||
echo " -b BASEDIR: consider tasks from BASEDIR, not ~/.forgebuild"
|
||||
}
|
||||
|
||||
# DVCS stuff (for tasks with source)
|
||||
clone () {
|
||||
dvcs="$1"
|
||||
src="$2"
|
||||
dest="$3"
|
||||
if [[ "$dvcs" = "git" ]]; then
|
||||
git clone --recursive "$2" "$3"
|
||||
else
|
||||
echo "UNIMPLEMENTED"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Checks for updates, if any download them
|
||||
# Returns:
|
||||
# - 0 when no updates
|
||||
# - 1 when updates were fetched
|
||||
# - anything else when there was an error
|
||||
updates() {
|
||||
dvcs="$1"
|
||||
# TODO: non-master primary branch
|
||||
[ -z "$2" ] && p_branch="master" || p_branch="$2"
|
||||
case "$dvcs" in
|
||||
"git")
|
||||
# Refresh remote before comparing with local
|
||||
if ! git fetch --quiet origin; then
|
||||
error pull_failed
|
||||
return 2
|
||||
fi
|
||||
git diff --quiet remotes/origin/$p_branch
|
||||
if [[ $? != 0 ]]; then
|
||||
info pull
|
||||
# Do not invoke an editor when merging submodule updates (--no-edit)
|
||||
#if ! git pull --quiet; then
|
||||
if ! git pull origin $p_branch; then
|
||||
error pull_failed
|
||||
return 3
|
||||
fi
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
;;
|
||||
*)
|
||||
echo "UNIMPLEMENTED"
|
||||
return 4
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Checks for submodule updates
|
||||
# Returns 0 for no updates, 1 for updates performed
|
||||
# and anything else when there was an error
|
||||
subupdates() {
|
||||
dvcs="$1"
|
||||
case "$dvcs" in
|
||||
"git")
|
||||
# List submodule paths
|
||||
FOUND_UPDATES=0
|
||||
DIR="$(pwd)"
|
||||
for submodule in $(git config --file .gitmodules --get-regexp path | awk '{ print $2 }'); do
|
||||
cd $submodule
|
||||
branch="$(git rev-parse --abbrev-ref HEAD)"
|
||||
updates git
|
||||
res=$?
|
||||
cd $DIR
|
||||
[ $res -eq 0 ] && continue # No updates found, skip to next submodule
|
||||
[ $res -eq 1 ] && FOUND_UPDATES=1 && continue # Found updates, try next submodule
|
||||
# There was an error, abort
|
||||
return $res
|
||||
done
|
||||
return $FOUND_UPDATES
|
||||
;;
|
||||
*)
|
||||
echo "UNIMPLEMENTED"
|
||||
return 4
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Logging is done with the LOG="debug|info|error" environment variable
|
||||
if [ ! -z $LOG ] && [ "$LOG" != "" ]; then
|
||||
case $LOG in
|
||||
|
@ -230,43 +309,36 @@ for p_name in ${PROJECTS[*]}; do
|
|||
fi
|
||||
debug already_cloned
|
||||
cd "$p_dir"
|
||||
# Refresh remote before comparing with local
|
||||
if ! git fetch --quiet origin; then
|
||||
error pull_failed
|
||||
exit 1
|
||||
fi
|
||||
git diff --quiet remotes/origin/$p_branch
|
||||
if [[ $? != 0 ]]; then
|
||||
info pull
|
||||
if ! git pull --quiet; then #--recurse-submodules; then
|
||||
error pull_failed
|
||||
exit 1
|
||||
fi
|
||||
run $p_name
|
||||
# If no update was found, we can still force rebuild with -f/--force
|
||||
elif [[ $FORCE = 1 ]]; then
|
||||
debug forcing
|
||||
run $p_name
|
||||
else
|
||||
# No update on the primary branch, but maybe there's a submodule update?
|
||||
if [ -f $BASEDIR/$p_name.subupdates ]; then
|
||||
git submodule foreach --recursive 'if ! git fetch --quiet origin; then\
|
||||
error pull_failed\
|
||||
exit 1\
|
||||
fi\
|
||||
git diff --quiet remotes/origin/$(git rev-parse --abbrev-ref HEAD)\
|
||||
if [[ $? != 0 ]]; then\
|
||||
info pull\
|
||||
if ! git pull --quiet; then\
|
||||
error pull_failed\
|
||||
exit 1\
|
||||
fi\
|
||||
fi'
|
||||
|
||||
updates git "$p_branch"
|
||||
res="$?"
|
||||
case "$res" in
|
||||
"0")
|
||||
if [[ $FORCE = 1 ]]; then
|
||||
debug forcing
|
||||
run $p_name
|
||||
else
|
||||
# Submodule updates, maybe?
|
||||
if [ ! -f $BASEDIR/$p_name.subupdates ]; then
|
||||
debug no_update
|
||||
continue
|
||||
fi
|
||||
subupdates git > /dev/stderr
|
||||
subres=$?
|
||||
[ $subres -eq 0 ] && debug no_update && continue
|
||||
[ ! $subres -eq 1 ] && echo "$subres" && continue # subupdates errored
|
||||
run $p_name
|
||||
fi
|
||||
;;
|
||||
"1")
|
||||
run $p_name
|
||||
else
|
||||
debug no_update
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
# Updates errored, skip task
|
||||
continue
|
||||
;;
|
||||
esac
|
||||
|
||||
done
|
||||
|
||||
# Check the PID in lockfile is still ours, we don't want
|
||||
|
|
Loading…
Reference in New Issue