mercurial (hg) support

This commit is contained in:
southerntofu 2020-09-17 20:13:38 +02:00
parent 3dd1343ec8
commit fc387c377b
1 changed files with 86 additions and 32 deletions

View File

@ -73,12 +73,18 @@ clone () {
dvcs="$1"
src="$2"
dest="$3"
if [[ "$dvcs" = "git" ]]; then
git clone --recursive "$2" "$3"
else
echo "UNIMPLEMENTED"
exit 1
fi
case "$dvcs" in
"git")
git clone --recursive "$2" "$3"
;;
"mercurial"|"hg")
hg clone "$2" "$3"
;;
*)
echo "UNIMPLEMENTED"
exit 1
;;
esac
}
# Checks for updates, if any download them
@ -88,8 +94,6 @@ clone () {
# - 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
@ -97,12 +101,11 @@ updates() {
error pull_failed
return 2
fi
p_branch="$(branch git)"
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
if ! git pull origin $p_branch --quiet; then
error pull_failed
return 3
fi
@ -110,6 +113,18 @@ updates() {
fi
return 0
;;
"mercurial"|"hg")
if hg incoming; then
info pull
if ! hg pull; then
error pull_failed
return 3
fi
return 1
else
return 0
fi
;;
*)
echo "UNIMPLEMENTED"
return 4
@ -117,6 +132,26 @@ updates() {
esac
}
# Checkout a specific branch/commit
# returns 0 on success, 1 if the checkout failed
# 2 if the backend is unknown
checkout () {
dvcs="$1"
target="$2"
case "$dvcs" in
"git")
git checkout $target
;;
"mercurial"|"hg")
hg update $target
;;
*)
echo "UNIMPLEMENTED"
exit 2
;;
esac
}
# Checks for submodule updates
# Returns 0 for no updates, 1 for updates performed
# and anything else when there was an error
@ -129,7 +164,6 @@ subupdates() {
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
@ -147,6 +181,24 @@ subupdates() {
esac
}
# Print the current branch for specified DVCS
# Return 0 when ok, 1 on error, 2 on unknown DVCS
branch () {
dvcs="$1"
case "$dvcs" in
"git")
git rev-parse --abbrev-ref HEAD || exit 1
;;
"mercurial"|"hg")
hg identify -b || exit 1
;;
*)
echo "UNIMPLEMENTED"
exit 2
;;
esac
}
# Logging is done with the LOG="debug|info|error" environment variable
if [ ! -z $LOG ] && [ "$LOG" != "" ]; then
case $LOG in
@ -274,35 +326,36 @@ for p_name in ${PROJECTS[*]}; do
continue
fi
# checkout a specific branch/commit
if [ -f $BASEDIR/$p_name.checkout ]; then
p_branch="$(cat $BASEDIR/$p_name.checkout)"
export i18n_branch="$p_branch"
info to_branch
else
# TODO: support non-master primary branch
p_branch="master"
export i18n_branch="$p_branch"
debug default_branch
fi
# So we have a source, check the associated DVCS
[ -f $BASEDIR/$p_name.dvcs ] && dvcs="$(cat $BASEDIR/$p_name.dvcs)" || dvcs="git"
p_dir="$BASEDIR/.$p_name"
if [ ! -d $p_dir ]; then
source="$(cat $BASEDIR/$p_name.source)"
export i18n_source="$source"
info clone
# Don't forget the git submodules!
if ! git clone --recursive "$source" "$p_dir"; then
if ! clone "$dvcs" "$source" "$p_dir"; then
error clone_failed
exit 1
fi
cd $p_dir
if [[ "$p_branch" != "master" ]]; then
debug checkout
if ! git checkout "$p_branch"; then
# checkout a specific branch/commit
if [ -f $BASEDIR/$p_name.checkout ]; then
p_branch="$(cat $BASEDIR/$p_name.checkout)"
export i18n_branch="$p_branch"
info to_branch
debug checkout
if ! checkout $dvcs "$p_branch"; then
error checkout_failed
exit 1
fi
fi
else
p_branch="$(branch $dvcs)"
export i18n_branch="$p_branch"
debug default_branch
fi
run $p_name
# Skip to the next task!
continue
@ -310,7 +363,8 @@ for p_name in ${PROJECTS[*]}; do
debug already_cloned
cd "$p_dir"
updates git "$p_branch"
# Omit "" on p_branch so if it's empty it's not registered as argument (and the default is used)
updates $dvcs $p_branch
res="$?"
case "$res" in
"0")
@ -323,10 +377,10 @@ for p_name in ${PROJECTS[*]}; do
debug no_update
continue
fi
subupdates git > /dev/stderr
subupdates $dvcs
subres=$?
[ $subres -eq 0 ] && debug no_update && continue
[ ! $subres -eq 1 ] && echo "$subres" && continue # subupdates errored
[ ! $subres -eq 1 ] && continue # subupdates errored
run $p_name
fi
;;