cleanup and review fix-remotes
authorErez Zadok <ezk@cs.sunysb.edu>
Sun, 8 May 2022 18:47:57 +0000 (14:47 -0400)
committerErez Zadok <ezk@cs.sunysb.edu>
Sun, 8 May 2022 18:47:57 +0000 (14:47 -0400)
fix-remotes.sh

index c35304ba1d7f35dd3a46eee159d8eac6ec251ec6..dd28fcc4ebb8f870b02a9f22907c6f9de8f417ef 100755 (executable)
@@ -4,6 +4,8 @@
 FSL_GIT="ssh://git.fsl.cs.sunysb.edu/scm/git"
 KORG_GIT="git://git.kernel.org/pub/scm/linux/kernel/git"
 
+DEBUG="yes" # set to "no" to turn off debug
+
 # function to execute commands
 runcmd() {
     echo "CMD: $@"
@@ -29,9 +31,10 @@ fi
 if test -z "$1"; then
     THIS_REPO=`basename $PWD | sed -e 's/^wrapfs-//' -e 's/\.y$//'`
 else
-    THIS_REPO="$1"
+    THIS_REPO="$1"     # this is how you can "force" a wrapfs-latest clone
+                       # to rebase to a stable kernel say, wrapfs-5.18
 fi
-#echo THIS_REPO:$THIS_REPO
+test "$DEBUG" eq "yes" && echo THIS_REPO:$THIS_REPO
 case "$THIS_REPO" in
     2.6.* | 3.* | 4.* | 5.* | latest ) ;;
     * ) echo This repo is unknown: $THIS_REPO
@@ -39,17 +42,17 @@ case "$THIS_REPO" in
        ;;
 esac
 
-# find out the URL for the remote "origin"`
+# 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
 THIS_ORIGIN_URL=`git config --get remote.origin.url 2>/dev/null`
-#echo THIS_ORIGIN_URL=$THIS_ORIGIN_URL
-# expected origin URL
+test "$DEBUG" eq "yes" && echo THIS_ORIGIN_URL=$THIS_ORIGIN_URL
+# expected origin URL (for FSL git server)
 case "$THIS_REPO" in
     latest ) EXPECTED_ORIGIN_URL="$FSL_GIT/wrapfs-${THIS_REPO}.git" ;;
     * ) EXPECTED_ORIGIN_URL="$FSL_GIT/wrapfs-${THIS_REPO}.y.git" ;;
 esac
-#echo EXPECTED_ORIGIN_URL=$EXPECTED_ORIGIN_URL
+test "$DEBUG" eq "yes" && echo EXPECTED_ORIGIN_URL=$EXPECTED_ORIGIN_URL
 
 # set new remote URL as needed
 if test "$THIS_ORIGIN_URL" != "$EXPECTED_ORIGIN_URL" ; then
@@ -62,9 +65,9 @@ if test "$THIS_ORIGIN_URL" != "$EXPECTED_ORIGIN_URL" ; then
     fi
 fi
 
-# find out the URL for the remote "korg"`
+# find out the URL for the remote "korg"
 THIS_KORG_URL=`git config --get remote.korg.url 2>/dev/null`
-#echo THIS_KORG_URL=$THIS_KORG_URL
+test "$DEBUG" eq "yes" && echo THIS_KORG_URL=$THIS_KORG_URL
 # expected korg URL
 case "$THIS_REPO" in
     latest )
@@ -76,7 +79,7 @@ case "$THIS_REPO" in
        KORG_BRANCH="linux-${THIS_REPO}.y"
        ;;
 esac
-#echo EXPECTED_KORG_URL=$EXPECTED_KORG_URL
+test "$DEBUG" eq "yes" && echo EXPECTED_KORG_URL=$EXPECTED_KORG_URL
 
 # set new remote URL as needed
 if test "$THIS_KORG_URL" != "$EXPECTED_KORG_URL" ; then
@@ -91,18 +94,20 @@ 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/]+"`
+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
+       if git branch | grep -qP "^\*? +wrapfs$" ; then
                runcmd git branch -u origin/wrapfs wrapfs
        else
                runcmd git checkout -b wrapfs origin/wrapfs
        fi
 fi
 
+# Check if there are any other unknown branches
 EXP_BR="origin/master|origin/wrapfs|origin/guilt/wrapfs|korg/$KORG_BRANCH"
-BRANCHES=`git branch -r|grep -vP $EXP_BR`
-if [[ -n $BRANCHES ]]; then
+BRANCHES=`git branch -r | grep -vP $EXP_BR`
+if test -n "$BRANCHES" ; then
        echo -e "$0: Found Unexpected Remote Branches:"
-       echo "$BRANCHES"|xargs
+       echo "$BRANCHES"
+       exit 1
 fi