[X2Go-Commits] [maintenancescripts] 04/04: git/hooks: check branch names, allow non-fast-forwards and merges on specific branches, deny on other.

git-admin at x2go.org git-admin at x2go.org
Sun Feb 22 01:18:38 CET 2015


This is an automated email from the git hooks/post-receive script.

x2go pushed a commit to branch master
in repository maintenancescripts.

commit 4d17d3ac8efa15ee861b5c1db740edec6c8efb8e
Author: Mihai Moldovan <ionic at ionic.de>
Date:   Sun Feb 22 01:17:17 2015 +0100

    git/hooks: check branch names, allow non-fast-forwards and merges on specific branches, deny on other.
---
 git/hooks/update-script._acl_                |   25 +++++++++++++++------
 git/hooks/update-script._check+allow-merges_ |   30 ++++++++++++++++++--------
 git/hooks/update-script._check_              |   30 ++++++++++++++++++--------
 3 files changed, 60 insertions(+), 25 deletions(-)

diff --git a/git/hooks/update-script._acl_ b/git/hooks/update-script._acl_
index 6f9a372..7beea26 100755
--- a/git/hooks/update-script._acl_
+++ b/git/hooks/update-script._acl_
@@ -36,15 +36,26 @@ case "$1" in
     deny >/dev/null "You can't overwrite an existing tag"
     ;;
   refs/heads/*)
-    # No rebasing or rewinding
+    BRANCH="${1#refs/heads/}"
+
+    # No rebasing or rewinding on release, build or master branches.
     if expr "$2" : '0*$' >/dev/null; then
-      info "The branch '$1' is new..."
+      case "${BRANCH}" in
+        release/*|build-*|master|feature/*|bugfix/*) info "The branch '$1' is new..." ;;
+        *) deny >/dev/null "ERROR: Branch name does not meet the project policies. Please contact git-admin at x2go.org." ;;
+      esac
     else
-      # updating -- make sure it is a fast forward
-      mb=$(git-merge-base "$2" "$3")
-      case "$mb,$2" in
-        "$2,$mb") info "Update is fast-forward" ;;
-        *)        noff=y; info "This is not a fast-forward update.";;
+      case "${BRANCH}" in
+        release/*|build-*|master)
+          # updating -- make sure it is a fast forward
+          mb=$(git-merge-base "$2" "$3")
+          case "$mb,$2" in
+            "$2,$mb") info "Update is fast-forward" ;;
+            *)        noff=y; info "This is not a fast-forward update.";;
+          esac
+          ;;
+        feature/*|bugfix/*) info "Not checking for non-fast-forwards on ${BRANCH}." ;;
+        *) deny >/dev/null "ERROR: Branch name does not meet the project policies. Please contact git-admin at x2go.org." ;;
       esac
     fi
     ;;
diff --git a/git/hooks/update-script._check+allow-merges_ b/git/hooks/update-script._check+allow-merges_
index dbfd9e6..3be967e 100755
--- a/git/hooks/update-script._check+allow-merges_
+++ b/git/hooks/update-script._check+allow-merges_
@@ -97,17 +97,29 @@ case "$1" in
     [ -f "$GIT_DIR/$1" ] && deny >/dev/null "You can't overwrite an existing tag"
     ;;
   refs/heads/*)
-    # No rebasing or rewinding
+    BRANCH="${1#refs/heads/}"
+
+    # No rebasing or rewinding on release, build or master branches.
     if expr "$2" : '0*$' >/dev/null; then
-      info "The branch '$1' is new..."
+      case "${BRANCH}" in
+        release/*|build-*|master|feature/*|bugfix/*) info "The branch '$1' is new..." ;;
+        *) deny >/dev/null "ERROR: Branch name does not meet the project policies. Please contact git-admin at x2go.org." ;;
+      esac
     else
-      # updating -- make sure it contains no merge commits
-      [ -n "$(git rev-list --merges $2..$3)" ] && echowarn "WARNING: update contains a merge. Allowing merges by special policies for this project."
-      # updating -- make sure it is a fast forward
-      mb=$(git merge-base "$2" "$3")
-      case "$mb,$2" in
-        "$2,$mb") info "Update is fast-forward" ;;
-        *)        deny > /dev/null "ERROR: This is not a fast-forward update. History has been rewritten." ;;
+      case "${BRANCH}" in
+        release/*|build-*|master)
+          # updating -- make sure it contains no merge commits
+          [ -n "$(git rev-list --merges $2..$3)" ] && echowarn "WARNING: update contains a merge. Allowing merges by special policies for this project."
+
+          # updating -- make sure it is a fast forward
+          mb=$(git merge-base "$2" "$3")
+          case "$mb,$2" in
+            "$2,$mb") info "Update is fast-forward" ;;
+            *)        deny > /dev/null "ERROR: This is not a fast-forward update. History has been rewritten." ;;
+          esac
+          ;;
+        feature/*|bugfix/*) info "Not checking for non-fast-forwards or merges on ${BRANCH}." ;;
+        *) deny >/dev/null "ERROR: Branch name does not meet the project policies. Please contact git-admin at x2go.org." ;;
       esac
     fi
     for REVISION in $(git rev-list --reverse "$2..$3") ; do
diff --git a/git/hooks/update-script._check_ b/git/hooks/update-script._check_
index f224d3a..c8fd284 100755
--- a/git/hooks/update-script._check_
+++ b/git/hooks/update-script._check_
@@ -95,17 +95,29 @@ case "$1" in
     [ -f "$GIT_DIR/$1" ] && deny >/dev/null "You can't overwrite an existing tag"
     ;;
   refs/heads/*)
-    # No rebasing or rewinding
+    BRANCH="${1#refs/heads/}"
+
+    # No rebasing or rewinding on release, build or master branches.
     if expr "$2" : '0*$' >/dev/null; then
-      info "The branch '$1' is new..."
+      case "${BRANCH}" in
+        release/*|build-*|master|feature/*|bugfix/*) info "The branch '$1' is new..." ;;
+        *) deny >/dev/null "ERROR: Branch name does not meet the project policies. Please contact git-admin at x2go.org." ;;
+      esac
     else
-      # updating -- make sure it contains no merge commits
-      [ -n "$(git rev-list --merges $2..$3)" ] && deny > /dev/null "ERROR: update contains a merge."
-      # updating -- make sure it is a fast forward
-      mb=$(git merge-base "$2" "$3")
-      case "$mb,$2" in
-        "$2,$mb") info "Update is fast-forward" ;;
-        *)        deny > /dev/null "ERROR: This is not a fast-forward update. History has been rewritten." ;;
+      case "${BRANCH}" in
+        release/*|build-*|master)
+          # updating -- make sure it contains no merge commits
+          [ -n "$(git rev-list --merges $2..$3)" ] && deny > /dev/null "ERROR: update contains a merge."
+
+          # updating -- make sure it is a fast forward
+          mb=$(git merge-base "$2" "$3")
+          case "$mb,$2" in
+            "$2,$mb") info "Update is fast-forward" ;;
+            *)        deny > /dev/null "ERROR: This is not a fast-forward update. History has been rewritten." ;;
+          esac
+          ;;
+        feature/*|bugfix/*) info "Not checking for non-fast-forwards or merges on ${BRANCH}." ;;
+        *) deny >/dev/null "ERROR: Branch name does not meet the project policies. Please contact git-admin at x2go.org." ;;
       esac
     fi
     for REVISION in $(git rev-list --reverse "$2..$3") ; do

--
Alioth's /srv/git/_hooks_/post-receive-email on /srv/git/code.x2go.org/maintenancescripts.git


More information about the x2go-commits mailing list