Added korg, wrapfs remotes and tracking local wrapfs to remote wrapfs
authorrohit <rohit>
Fri, 30 Mar 2018 13:58:05 +0000 (13:58 +0000)
committerrohit <rohit>
Fri, 30 Mar 2018 13:58:05 +0000 (13:58 +0000)
wrapfs-fix-branch.sh

index 3ef137f55c0580d184874a6697fd5cebddf64915..a7f9a883f503f0ef33c147498efa885ebf4e0820 100755 (executable)
@@ -2,32 +2,41 @@
 
 set -u -e
 
-_=${LINUX_VERSION:=""}
 _=${LINUX_REPO:=""}
 _=${LINUX_BRANCH:=""}
-_=${WRAPFS_REPO:=""}
-_=${LOG_FILE:=""}
+_=${LOG_FILE:="/tmp/wrapfs-fix-branch.log"}
 _=${SCRIPT:=$(readlink -f $0)}
 _=${LOCATION:=$(dirname $SCRIPT)}
 
-
+# check if the script is running for a git repository or not 
 if [ ! -d .git ]; then
     echo "Please run this script in a git directory."
     exit
 fi
+
 LINUX_PREFIX="git://git.kernel.org/pub/scm/linux/kernel/git"
+LINUX_BRANCH="master"
 
-WRAPFS_PREFIX="git://git.fsl.cs.sunysb.edu"
+# fetch the wrapfs url from .git/config 
+WRAPFS_URL=`git config --get-regexp remote.origin.url wrapfs | cut -f 2 -d ' '`
 
-WRAPFS_DIR=${PWD##*/}
+if [ -z "${WRAPFS_URL:+x}" ]; then
+    echo "Wrapfs url missing .git/config"
+    exit 1
+fi
 
-WRAPFS_REPO="${WRAPFS_DIR}.git"
+# fetch the wrapfs repository name from the wrapfs-url
+WRAPFS_REPO=`git config --get-regexp remote.origin.url wrapfs | sed 's/.*\///g'`
 
-LINUX_BRANCH="master"
+if [ -z "${WRAPFS_REPO:+x}" ]; then
+    echo "Missing repository name in url $WRAPFS_URL"
+    exit 1
+fi
 
-LOG_FILE="/tmp/log-${WRAPFS_DIR}"
+# Log info in a file
+LOG_FILE="/tmp/log-${WRAPFS_REPO}"
 
+# function to execute commands 
 runcmd() {
     echo "----------------------------------------------------------------------" 2>&1 | tee -a $LOG_FILE
     echo "CMD: $@" 2>&1 | tee -a $LOG_FILE
@@ -39,53 +48,67 @@ runcmd() {
     fi
 }
 
-case "$WRAPFS_DIR" in
-    wrapfs-latest)
+case "$WRAPFS_REPO" in
+    wrapfs-latest*)
        LINUX_REPO="torvalds/linux.git"
         LINUX_BRANCH="master"
        ;;
     wrapfs-2.* | wrapfs-3.* | wrapfs-4.* ) 
        LINUX_REPO="stable/linux-stable.git"
-        LINUX_BRANCH=$(echo $WRAPFS_DIR | sed s/wrapfs/linux/g)
-
-        # make sure it ends with *.y.git
-        if [[ "$LINUX_BRANCH" != *".y" ]]; then
-            LINUX_BRANCH="$LINUX_BRANCH.y"
-        fi
+        LINUX_BRANCH=$(echo $WRAPFS_REPO | sed s/wrapfs/linux/g | sed s/\.git//g)
        ;;
     * )
-        echo "Please run the script in a wrapfs git repository."
+        echo "$WRAPFS_REPO: Unidentified repository. Script support only for wrapfs repository."
         exit 1
 esac
 
-# make sure it ends with *.y.git
-if [[ "$WRAPFS_REPO" != *".y" ]]; then
-    wrapfs_repo=`git config --get-regexp "remote.origin.url" "wrapfs" | sed 's/.*\///g'`
-    if [ "$wrapfs_repo" != "" ]; then 
-        WRAPFS_REPO=$wrapfs_repo
-    else
-        WRAPFS_REPO=$(echo $WRAPFS_REPO | sed s/git/y.git/g)
-    fi
-    
-fi
-
+# Reset merge rename limit
 runcmd git config merge.renameLimit 999999
 
-# check if remote already exists
+# check if remote 'wrapfs' already exists
 if `git remote | egrep -q ^wrapfs` ; then
     echo "git remote wrapfs already exists"
     runcmd git remote -v
 else
-    runcmd git remote add wrapfs $WRAPFS_PREFIX/$WRAPFS_REPO
+    runcmd git remote add wrapfs $WRAPFS_URL
+fi
+
+# check if remote 'korg' already exists
+if `git remote | egrep -q ^korg` ; then
+    echo "git remote korg already exists"
+    runcmd git remote -v
+else
+    runcmd git remote add korg $LINUX_PREFIX/$LINUX_REPO
 fi
+
+# check if local branch 'wrapfs' already exists
 if `git branch | egrep -q wrapfs` ; then
-    echo "git branch wrapfs already exists"
+    echo "git local branch wrapfs already exists"
     runcmd git branch
 else
     runcmd git branch wrapfs
 fi
-runcmd git fetch --tags wrapfs
-runcmd git branch wrapfs -u wrapfs/master
-runcmd git remote set-url origin $LINUX_PREFIX/$LINUX_REPO
-runcmd git fetch --tags origin
-runcmd git reset --hard origin/$LINUX_BRANCH
+
+# Fetch correct tags for respective linux version
+runcmd git fetch korg --tags $LINUX_BRANCH
+runcmd git reset --hard korg/$LINUX_BRANCH
+
+# Reset master to linux code base
+runcmd git push -f origin master
+
+# check if remote branch 'wrapfs' already exists
+# configure local wrapfs branch to remote wrapfs branch
+wrapfs_remote_branch=`git ls-remote --heads $WRAPFS_URL wrapfs`
+if [ -z "${wrapfs_remote_branch:+x}" ]; then
+    echo "git remote branch wrapfs does not exists"
+    runcmd git push origin wrapfs
+    runcmd git push --set-upstream wrapfs wrapfs
+else
+    runcmd git branch -r
+fi
+
+# delete origin/wrapfs remote branch
+origin_remote_branch=`git ls-remote --heads $WRAPFS_URL origin/wrapfs`
+if [ -n "${origin_remote_branch:+x}" ]; then
+    runcmd git branch -r -d origin/wrapfs
+fi