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"
|
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
|
# Logging is done with the LOG="debug|info|error" environment variable
|
||||||
if [ ! -z $LOG ] && [ "$LOG" != "" ]; then
|
if [ ! -z $LOG ] && [ "$LOG" != "" ]; then
|
||||||
case $LOG in
|
case $LOG in
|
||||||
|
@ -230,43 +309,36 @@ for p_name in ${PROJECTS[*]}; do
|
||||||
fi
|
fi
|
||||||
debug already_cloned
|
debug already_cloned
|
||||||
cd "$p_dir"
|
cd "$p_dir"
|
||||||
# Refresh remote before comparing with local
|
|
||||||
if ! git fetch --quiet origin; then
|
updates git "$p_branch"
|
||||||
error pull_failed
|
res="$?"
|
||||||
exit 1
|
case "$res" in
|
||||||
fi
|
"0")
|
||||||
git diff --quiet remotes/origin/$p_branch
|
if [[ $FORCE = 1 ]]; then
|
||||||
if [[ $? != 0 ]]; then
|
debug forcing
|
||||||
info pull
|
run $p_name
|
||||||
if ! git pull --quiet; then #--recurse-submodules; then
|
else
|
||||||
error pull_failed
|
# Submodule updates, maybe?
|
||||||
exit 1
|
if [ ! -f $BASEDIR/$p_name.subupdates ]; then
|
||||||
fi
|
debug no_update
|
||||||
run $p_name
|
continue
|
||||||
# If no update was found, we can still force rebuild with -f/--force
|
fi
|
||||||
elif [[ $FORCE = 1 ]]; then
|
subupdates git > /dev/stderr
|
||||||
debug forcing
|
subres=$?
|
||||||
run $p_name
|
[ $subres -eq 0 ] && debug no_update && continue
|
||||||
else
|
[ ! $subres -eq 1 ] && echo "$subres" && continue # subupdates errored
|
||||||
# No update on the primary branch, but maybe there's a submodule update?
|
run $p_name
|
||||||
if [ -f $BASEDIR/$p_name.subupdates ]; then
|
fi
|
||||||
git submodule foreach --recursive 'if ! git fetch --quiet origin; then\
|
;;
|
||||||
error pull_failed\
|
"1")
|
||||||
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'
|
|
||||||
run $p_name
|
run $p_name
|
||||||
else
|
;;
|
||||||
debug no_update
|
*)
|
||||||
fi
|
# Updates errored, skip task
|
||||||
fi
|
continue
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# Check the PID in lockfile is still ours, we don't want
|
# Check the PID in lockfile is still ours, we don't want
|
||||||
|
|
Loading…
Reference in New Issue