[sysadmin-bin: 2/6] Update bash scripts to not hardcode the mainline branch name



commit a6e7fb16dcf28041308f5b54b36f7fdc20985cf3
Author: Michael Gratton <mike vee net>
Date:   Wed Apr 3 02:20:09 2019 +1100

    Update bash scripts to not hardcode the mainline branch name

 git/post-receive-notify-cia         |  6 +++++-
 git/post-receive-notify-kgb         |  6 +++++-
 git/post-receive-update-description | 10 +++++++---
 git/pre-receive-check-maintainers   | 10 +++++++---
 git/pre-receive-check-po            |  6 +++++-
 git/pre-receive-check-policy        | 11 ++++++++---
 git/update-all-info                 |  9 +++++++--
 7 files changed, 44 insertions(+), 14 deletions(-)
---
diff --git a/git/post-receive-notify-cia b/git/post-receive-notify-cia
index f73d69b..f44c792 100755
--- a/git/post-receive-notify-cia
+++ b/git/post-receive-notify-cia
@@ -25,6 +25,10 @@ absdir=$(cd $GIT_DIR && pwd)
 GNOME_GIT_MODULE=$(basename ${absdir%.git})
 export GNOME_GIT_MODULE
 
+# Get the repo's mainline branch name
+mainline=$(git symbolic-ref --quiet --short HEAD)
+mainline=${mainline:-"master"}
+
 # Adapted from:
 #  http://kitenet.net/~joey/blog/entry/lazyweb:_git_cia_hooks/
 while read oldrev newrev refname; do
@@ -46,7 +50,7 @@ while read oldrev newrev refname; do
     fi
 
     branchname=${refname#refs/heads/}
-    [ "$branchname" = "master" ] && branchname=
+    [ "$branchname" = "$mainline" ] && branchname=
 
     # Take all the branches in the repo, as "^/ref/heads/branchname", other than the
     # branch we are actualy committing to, and exclude commits already on those
diff --git a/git/post-receive-notify-kgb b/git/post-receive-notify-kgb
index 160b01c..b86c2ab 100755
--- a/git/post-receive-notify-kgb
+++ b/git/post-receive-notify-kgb
@@ -8,6 +8,10 @@ BASEDIR=$(dirname $ABSDIR)
 REPOSITORY_ID=$(basename "$PWD")
 REPOSITORY_ID=${REPOSITORY_ID%.git}
 
+# Get the repo's mainline branch name
+mainline=$(git symbolic-ref --quiet --short HEAD)
+mainline=${mainline:-"master"}
+
 if [[ $BASEDIR = '/var/opt/gitlab/git-data/repositories/GNOME' || $BASEDIR = 
'/var/opt/gitlab/git-data/repositories/Infrastructure' || $BASEDIR = '/git' ]]; then
-      egrep 'refs/heads/(master|gtk\-|glib\-|gnome\-)' | kgb-client --conf 
/home/admin/KGB/kgb-client-$REPOSITORY_ID.conf --repository git --git-reflog - > /dev/null 2>&1
+      egrep "refs/heads/($mainline|gtk\-|glib\-|gnome\-)" | kgb-client --conf 
/home/admin/KGB/kgb-client-$REPOSITORY_ID.conf --repository git --git-reflog - > /dev/null 2>&1
 fi
diff --git a/git/post-receive-update-description b/git/post-receive-update-description
index 604707a..ffa7748 100755
--- a/git/post-receive-update-description
+++ b/git/post-receive-update-description
@@ -10,6 +10,10 @@ GIT_DIR=$(git rev-parse --git-dir 2>/dev/null)
 absdir=$(cd $GIT_DIR && pwd)
 projectshort=$(basename ${absdir%.git})
 
+# Get the repo's mainline branch name
+mainline=$(git symbolic-ref --quiet --short HEAD)
+mainline=${mainline:-"master"}
+
 update_info_from_doap() {
     rev=$1
     path=$2
@@ -33,13 +37,13 @@ update_info() {
        return 0
     fi
 
-    if [ "$branchname" != "master" ] ; then
-       # Only pay attention to the master branch
+    if [ "$branchname" != "$mainline" ] ; then
+       # Only pay attention to the mainline branch
        return 0
     fi
 
     if expr $newrev : "^0\+$" > /dev/null 2>&1; then
-        # Branch deletion; (shouldn't really happen for the master branch)
+        # Branch deletion; (shouldn't really happen for the mainline branch)
        return 0
     fi
 
diff --git a/git/pre-receive-check-maintainers b/git/pre-receive-check-maintainers
index 8ff8194..9c243ec 100755
--- a/git/pre-receive-check-maintainers
+++ b/git/pre-receive-check-maintainers
@@ -12,6 +12,10 @@ GIT_DIR=$(git rev-parse --git-dir 2>/dev/null)
 absdir=$(cd $GIT_DIR && pwd)
 projectshort=$(basename ${absdir%.git})
 
+# Get the repo's mainline branch name
+mainline=$(git symbolic-ref --quiet --short HEAD)
+mainline=${mainline:-"master"}
+
 check_maintainers() {
     oldrev=$1
     newrev=$2
@@ -23,8 +27,8 @@ check_maintainers() {
        return 0
     fi
 
-    if [ "$branchname" != "master" ] ; then
-       # maintainer info only required on the master branch
+    if [ "$branchname" != "$mainline" ] ; then
+       # maintainer info only required on the mainline branch
        return 0
     fi
 
@@ -34,7 +38,7 @@ check_maintainers() {
     fi
 
     if expr $newrev : "^0\+$" > /dev/null 2>&1; then
-        # Branch deletion; (shouldn't really happen for the master branch)
+        # Branch deletion; (shouldn't really happen for the mainline branch)
        return 0
     fi
 
diff --git a/git/pre-receive-check-po b/git/pre-receive-check-po
old mode 100644
new mode 100755
index ce6a55b..a248121
--- a/git/pre-receive-check-po
+++ b/git/pre-receive-check-po
@@ -99,6 +99,10 @@ check_pos() {
     newrev=$2
     refname=$3
 
+    # Get the repo's mainline branch name
+    mainline=$(git symbolic-ref --quiet --short HEAD)
+    mainline=${mainline:-"master"}
+
     branchname=${refname#refs/heads/}
     if [ "$branchname" = "$refname" ] ; then
         # not a branch update
@@ -106,7 +110,7 @@ check_pos() {
     fi
 
     branch_message=
-    if [ "$branchname" != "master" ] ; then
+    if [ "$branchname" != "$mainline" ] ; then
        branch_message=" (When updating branch '$branchname'.)"
     fi
 
diff --git a/git/pre-receive-check-policy b/git/pre-receive-check-policy
index b6d940e..ad379fb 100755
--- a/git/pre-receive-check-policy
+++ b/git/pre-receive-check-policy
@@ -14,6 +14,10 @@ server=gitlab.gnome.org
 
 GIT_DIR=$(git rev-parse --git-dir 2>/dev/null)
 
+# Get the repo's mainline branch name
+mainline=$(git symbolic-ref --quiet --short HEAD)
+mainline=${mainline:-"master"}
+
 in_import() {
     test -e "$GIT_DIR/pending"
 }
@@ -116,9 +120,9 @@ check_ref_update() {
             is_protected=false
             case $branchname in
                 wip/*) is_wip=true ;;
-                master) is_protected=true ;;
                 gnome-*) is_protected=true ;;
                 gimp-*) is_protected=true ;;
+                "$mainline") is_protected=true ;;
             esac
 
            range=
@@ -137,8 +141,9 @@ check_ref_update() {
                delete)
                    # We really don't like to allow deleting any branch, but
                    # people need to do it to clean up accidentally pushed
-                   # branches. Deleting master, however, has no purpose other
-                   # than getting around the no-fast-forward restrictions
+                   # branches. Deleting protected branches, however, has no
+                   # purpose other than getting around the no-fast-forward
+                   # restrictions
                    if [ "$is_protected" = true  ] ; then
                        cat <<- EOF >&2
                                ---
diff --git a/git/update-all-info b/git/update-all-info
index 39f74da..240b127 100755
--- a/git/update-all-info
+++ b/git/update-all-info
@@ -14,8 +14,13 @@ function process_repos() {
                projectshort=$(basename ${absdir%.git})
 
                export GIT_DIR=$r
-               if git cat-file -e master:$projectshort.doap 2>/dev/null ; then
-                   git cat-file blob master:$projectshort.doap | $BINDIR/extract-doap-info $r
+
+               # Get the repo's mainline branch name
+               mainline=$(git symbolic-ref --quiet --short HEAD)
+               mainline=${mainline:-"master"}
+
+               if git cat-file -e $mainline:$projectshort.doap 2>/dev/null ; then
+                   git cat-file blob $mainline:$projectshort.doap | $BINDIR/extract-doap-info $r
                fi
            fi
        done


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]