check for unexpected remote branches in fix-remotes.sh
authoraburford <andrew.burford@stonybrook.edu>
Sun, 8 May 2022 16:55:19 +0000 (12:55 -0400)
committeraburford <andrew.burford@stonybrook.edu>
Sun, 8 May 2022 16:55:19 +0000 (12:55 -0400)
fix-remotes.sh

index fe7040cdf2c82c03d27e22b5de746d1637b5b98e..c35304ba1d7f35dd3a46eee159d8eac6ec251ec6 100755 (executable)
@@ -39,35 +39,9 @@ case "$THIS_REPO" in
        ;;
 esac
 
-# we could verify we have both master and wrapfs branches
-# as done below but I don't really see the purpose of this because
-# we are going to overwrite/add the origin and korg remote URL's anyway
-# so doing this gives us no actionable information. I feel like it just
-# confuses the user with what looks like an error but is actually something the
-# script is about to fix.
-#TMP_BR_LIST=/tmp/.tbr.$$
-#(
-#cat <<EOF
-#  origin/HEAD -> origin/master
-#  origin/guilt/wrapfs
-#  origin/master
-#  origin/wrapfs
-#EOF
-#) > $TMP_BR_LIST
-#EXP_BR_LIST=/tmp/.ebr.$$
-#git branch -r > $EXP_BR_LIST
-#if ! cmp $TMP_BR_LIST $EXP_BR_LIST &>/dev/null; then
-#    echo "Expected list of branches mismatched for `basename $PWD`"
-#    diff -u $TMP_BR_LIST $EXP_BR_LIST
-#    /bin/rm -f $TMP_BR_LIST $EXP_BR_LIST
-##    exit 1
-#fi
-#/bin/rm -f $TMP_BR_LIST $EXP_BR_LIST
-
 # find out the URL for the remote "origin"`
 # `git remote get-url origin` is the newest syntax but the syntax below
 # works on newer and older versions of git
-# so I'm not sure which is preferable
 THIS_ORIGIN_URL=`git config --get remote.origin.url 2>/dev/null`
 #echo THIS_ORIGIN_URL=$THIS_ORIGIN_URL
 # expected origin URL
@@ -114,3 +88,21 @@ if test "$THIS_KORG_URL" != "$EXPECTED_KORG_URL" ; then
        runcmd git remote set-url korg $EXPECTED_KORG_URL
     fi
 fi
+
+# grep out the upstream branch for wrapfs
+# and set upstream to origin/wrapfs if it isn't already
+WRAPFS_UPSTREAM=`git branch -vv|grep -oP "\*? +wrapfs\s+[0-9a-f]+ \[\K[a-z/]+"`
+if test "$WRAPFS_UPSTREAM" != "origin/wrapfs"; then
+       if git branch | grep -qP "^\*? +wrapfs$"; then
+               runcmd git branch -u origin/wrapfs wrapfs
+       else
+               runcmd git checkout -b wrapfs origin/wrapfs
+       fi
+fi
+
+EXP_BR="origin/master|origin/wrapfs|origin/guilt/wrapfs|korg/$KORG_BRANCH"
+BRANCHES=`git branch -r|grep -vP $EXP_BR`
+if [[ -n $BRANCHES ]]; then
+       echo -e "$0: Found Unexpected Remote Branches:"
+       echo "$BRANCHES"|xargs
+fi