summaryrefslogtreecommitdiffstats
path: root/switch_all_submodules_to_head_and_clean
diff options
context:
space:
mode:
Diffstat (limited to 'switch_all_submodules_to_head_and_clean')
-rwxr-xr-xswitch_all_submodules_to_head_and_clean63
1 files changed, 56 insertions, 7 deletions
diff --git a/switch_all_submodules_to_head_and_clean b/switch_all_submodules_to_head_and_clean
index 052ef59..5ca3d13 100755
--- a/switch_all_submodules_to_head_and_clean
+++ b/switch_all_submodules_to_head_and_clean
@@ -22,16 +22,20 @@ branch=`git symbolic-ref -q HEAD | sed "s|^refs/heads/||"`
if [[ -z "$branch" ]]; then
branch=`git branch --contains HEAD | egrep -v "no branch|detached" | head -n1 | cut -c 3-`
fi
-if [[ -z "$branch" ]] ||
- [[ -z "`git rev-parse --symbolic-full-name --remotes=\"*/$branch\"`" ]]; then
- echo "There is not active upstream branch. Exiting..."
+if [[ -z "$branch" ]]; then
+ echo "There is not active branch. Exiting..."
+ exit 1
+fi
+remote=`git config branch."$branch".remote`
+if [[ -z "$remote" ]]; then
+ echo "Active branch is not remote tracked. Exiting..."
exit 1
fi
# get git user
echobd "Preparing $(git rev-parse --show-toplevel | xargs -r basename) $branch branch for development use"
if [[ $1 == "" ]]; then
- gituser=`git config --local remote.origin.url | sed -n "s|\(https\?://\)\?\([^@]*\)@.*|\2|p" | grep -v "\(anonymous\|system\)"`
+ gituser=`git config --local remote.$remote.url | sed -n "s|\(https\?://\)\?\([^@]*\)@.*|\2|p" | grep -v "\(anonymous\|system\)"`
else
gituser=$1
fi
@@ -55,6 +59,10 @@ fi
# update module and submodules
updateModule() {
local MODULE
+ local REPO_URL
+ local REPO_PROTO
+ local REPO_MODULE
+ local REPO_WORKTREE
if [[ "$1" != "" ]]; then
MODULE=$1/
else
@@ -66,8 +74,21 @@ updateModule() {
git reset --hard HEAD
git clean -dxff
fi
+ git remote |
+ while read REMOTE; do
+ REPO_SERVER=$(git config remote."$REMOTE".url |
+ sed -n "s|^http[^/]*/*\([^@]*@\)\?\([^/]*\)/.*|\2|p")
+ if [ -x /usr/bin/fping ] && [ -n "$REPO_SERVER" ]; then
+ fping -q -r1 "$REPO_SERVER" || continue
+ fi
+ echo Fetching $REMOTE
+ git fetch $REMOTE --prune $GIT_NO_RECURSE_SUBMODULES
+ done
+ git branch | grep -x "* $branch" >/dev/null || \
git checkout $branch
- git pull --rebase --all --prune $GIT_NO_RECURSE_SUBMODULES
+ remote=`git config branch."$branch".remote`
+ [[ -n "$remote" ]] || return
+ git rebase $remote/$branch $branch
if [[ ! -z "`git status --porcelain $GIT_IGNORE_SUBMODULES`" ]]; then
git reset --hard HEAD
git clean -dxff
@@ -79,11 +100,17 @@ updateModule() {
else
sed -i "s/system@/$gituser@/g" $PARENTDIR/$MODULE.gitmodules
fi
- REPO_URL=$(git config --get remote.origin.url |\
+ REPO_URL=$(git config --get remote.$remote.url |\
sed "s|\(https\?://\)\?\([^@]*@\)\?\(.*\)/[^/]*$|\3|")
- REPO_PROTO=$(git config --get remote.origin.url |\
+ REPO_PROTO=$(git config --get remote.$remote.url |\
sed "s|\(https\?://\)\?\([^@]*@\)\?\(.*\)/[^/]*$|\1|")
REPO_MASTER=scm.trinitydesktop.org/scm/git
+ REPO_MODULE=$(git config --get remote.$remote.url |\
+ sed -e "s|\(https\?://\)\?\([^@]*@\)\?\(.*\)/\([^/]*\)$|\4|" -e "s|\.git$||")
+ REPO_GITDIR=$(git rev-parse --git-dir)
+ if [[ "${REPO_GITDIR/worktrees//}" != "$REPO_GITDIR" ]]; then
+ REPO_WORKTREE=${REPO_GITDIR%/[^/]*/worktrees/[^/]*}
+ fi
if [[ "$REPO_URL" != "$REPO_MASTER" ]]; then
sed -i "s#https\?://\([^@]*@\)\?$REPO_MASTER#$REPO_PROTO\1$REPO_URL#g" $PARENTDIR/$MODULE.gitmodules
fi
@@ -91,6 +118,28 @@ updateModule() {
while read submodule; do
echobd "Attempting to switch submodule ${MODULE}${submodule}"
cd $PARENTDIR/$MODULE
+ if [[ -n "$REPO_WORKTREE" ]] && [[ ! -e "$submodule/.git" ]]; then
+ REPO_LOCALTREE=$(git config --file .gitmodules --get submodule.$submodule.url | \
+ sed "s#^\(https\?://\)\?\([^@]*@\)\?$REPO_URL#$REPO_WORKTREE#g")
+ if [[ ! -d "$REPO_LOCALTREE" ]]; then
+ REPO_LOCALTREE=$REPO_LOCALTREE.git
+ fi
+ if [[ ! -d "$REPO_LOCALTREE" ]]; then
+ git clone --bare --config "remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*" \
+ "$(git config --file .gitmodules --get submodule.$submodule.url)" "$REPO_LOCALTREE"
+ fi
+ if [[ "$REPO_MODULE" != "tde" ]]; then
+ git config --file .gitmodules submodule.$submodule.url "$REPO_LOCALTREE"
+ else
+ (
+ cd $REPO_LOCALTREE &&
+ git fetch &&
+ git worktree add $PARENTDIR/$MODULE$submodule $branch &&
+ cd $PARENTDIR/$MODULE$submodule &&
+ git branch --set-upstream-to=origin/$branch
+ ) || continue
+ fi
+ fi
if [[ -z "`git config --get submodule.$submodule.url`" ]]; then
git submodule init -- $submodule
fi