[sysadmin-bin] Allow git hooks commit messages to appear on the GitLab web UI



commit a30e8cf98b332465a98045c1d6c3ed5f503d1447
Author: Andrea Veri <averi redhat com>
Date:   Fri Sep 10 12:01:31 2021 +0200

    Allow git hooks commit messages to appear on the GitLab web UI

 git/pre-receive-check-policy | 215 +++++++++++++++++++++++--------------------
 1 file changed, 114 insertions(+), 101 deletions(-)
---
diff --git a/git/pre-receive-check-policy b/git/pre-receive-check-policy
index cc4f2ec..794d474 100755
--- a/git/pre-receive-check-policy
+++ b/git/pre-receive-check-policy
@@ -16,6 +16,8 @@ server=gitlab.gnome.org
 mainline=$(git symbolic-ref --quiet --short HEAD)
 mainline=${mainline:-"master"}
 
+GITLAB_ERR_PREFIX='GL-HOOK-ERR:'
+
 check_commit() {
     commit=$1
 
@@ -23,55 +25,54 @@ check_commit() {
     case "$email" in
     *localhost.localdomain|*\(none\))
         cat <<- EOF >&2
-            ---
-            The commits you are trying to push contain the author email
-            address '$email'. Please configure your
-            username and email address. See:
-
-              https://wiki.gnome.org/Git/Help/AuthorEmail
-
-            For instructions about how to do this and how to fix your
-            existing commits.
-            ---
-        EOF
-        exit 1
-        ;;
+$GITLAB_ERR_PREFIX
+---
+The commits you are trying to push contain the author email
+address '$email'. Please configure your
+username and email address. See:
+
+  https://wiki.gnome.org/Git/Help/AuthorEmail
+
+For instructions about how to do this and how to fix your
+existing commits.
+---
+EOF
+    exit 1
+    ;;
     esac
 
     subject="$(git log $commit -1 --pretty=format:%s)"
     if expr "$subject" : ".*Merge branch.*of.*\(git\|ssh\):" > /dev/null 2>&1; then
         cat <<- EOF >&2
-            ---
-            The commit:
+$GITLAB_ERR_PREFIX
+---
+The commit:
 
-        EOF
-        git log $commit -1 >&2
-        cat <<- EOF >&2
+`git log $commit -1`
 
-            Looks like it was produced by typing 'git pull' without the --rebase
-            option when you had local changes. Running 'git  pull --rebase' now
-            will fix the problem. Then please try, 'git push' again. Please see:
+Looks like it was produced by typing 'git pull' without the --rebase
+option when you had local changes. Running 'git  pull --rebase' now
+will fix the problem. Then please try, 'git push' again. Please see:
 
-              https://wiki.gnome.org/Git/Help/ExtraMergeCommits
-            ---
-        EOF
+https://wiki.gnome.org/Git/Help/ExtraMergeCommits
+---
+EOF
         exit 1
     fi
 
     body="$(git log $commit -1 --pretty=format:%b)"
     if expr "$body" : ".*FIXME: need commit message" > /dev/null 2>&1; then
         cat <<- EOF >&2
-            ---
-            The commit:
+$GITLAB_ERR_PREFIX
+---
+The commit:
 
-            EOF
-        git log $commit -1 >&2
-        cat <<- EOF >&2
+`git log $commit -1`
 
-            Was created by git-bz from a plain diff. Please edit the commit message
-            to properly describe the commit using 'git commit --amend' or
-            (for an older commit) 'git rebase -i'. Then try 'git push' again.
-            EOF
+Was created by git-bz from a plain diff. Please edit the commit message
+to properly describe the commit using 'git commit --amend' or
+(for an older commit) 'git rebase -i'. Then try 'git push' again.
+EOF
         exit 1
     fi
 
@@ -114,12 +115,13 @@ check_ref_update() {
         create)
             if [ "x$branchname" = xHEAD ] ; then
             cat <<- EOF >&2
-                ---
-                You are trying to push the branch 'HEAD'.
-                ---
-                EOF
-            exit 1
-            fi
+$GITLAB_ERR_PREFIX
+---
+You are trying to push the branch 'HEAD'.
+---
+EOF
+        exit 1
+        fi
             range="$newrev"
             ;;
         delete)
@@ -129,11 +131,12 @@ check_ref_update() {
             # purpose other than getting around the no-fast-forward
             # restrictions
             if [ "$is_protected" = true  ] ; then
-                cat <<- EOF >&2
-                ---
-                You are trying to delete a protected branch.
-                ---
-                EOF
+cat <<- EOF >&2
+$GITLAB_ERR_PREFIX
+---
+You are trying to delete a protected branch.
+---
+EOF
             exit 1
             fi
             ;;
@@ -153,14 +156,15 @@ check_ref_update() {
 
             if [ "$nonfastforward" = true ] ; then
                 cat <<- EOF >&2
-                    ---
-                    You are trying to update the branch '$branchname' in a way that is not
-                    a fast-forward update. Please see:
-
-                        https://wiki.gnome.org/Git/Help/NonFastForward
-                    ---
-                    EOF
-                exit 1
+$GITLAB_ERR_PREFIX
+---
+You are trying to update the branch '$branchname' in a way that is not
+a fast-forward update. Please see:
+
+https://wiki.gnome.org/Git/Help/NonFastForward
+---
+EOF
+            exit 1
             fi
             ;;
             esac
@@ -193,34 +197,37 @@ check_ref_update() {
                 # Lightweight tag; we allow an import containing these
                 # tags, but forbid them in general
                 cat <<- EOF >&2
-                    ---
-                    You are trying to push the lightweight tag '$tagname'. You should either
-                    make use of a signed (-s) or annotated tag (-a) instead. More details at:
-
-                      https://wiki.gnome.org/Git/Help/LightweightTags
-                    ---
-                    EOF
+$GITLAB_ERR_PREFIX
+---
+You are trying to push the lightweight tag '$tagname'. You should either
+make use of a signed (-s) or annotated tag (-a) instead. More details at:
+
+https://wiki.gnome.org/Git/Help/LightweightTags
+---
+EOF
                 exit 1
                 ;;
             tag)
                 # Annotated tag
                 if [ "${tagname}" = "HEAD" ]; then
                     cat <<- EOF >&2
-                    ---
-                    You are trying to push a tag named '$tagname'. This is not allowed.
-                    ---
-                    EOF
+$GITLAB_ERR_PREFIX
+---
+You are trying to push a tag named '$tagname'. This is not allowed.
+---
+EOF
                 exit 1
                 fi
                 ;;
             *)
                 # git is happy to allow tagging random objects, we aren't
                 cat <<- EOF >&2
-                    ---
-                    You are trying to push the tag '$tagname', which points to an object
-                    of type $object_type. (It should point to a commit or tag object.)
-                    ---
-                    EOF
+$GITLAB_ERR_PREFIX
+---
+You are trying to push the tag '$tagname', which points to an object
+of type $object_type. (It should point to a commit or tag object.)
+---
+EOF
                 exit 1
                 ;;
             esac
@@ -234,23 +241,25 @@ check_ref_update() {
             # rejecting its creation was added to policy.
             if [ 'x'"$tagname" != 'xHEAD' ] ; then
             cat <<- EOF >&2
-                ---
-                You are trying to delete the tag '$tagname'.
+$GITLAB_ERR_PREFIX
+---
+You are trying to delete the tag '$tagname'.
 
-                  https://wiki.gnome.org/Git/Help/TagUpdates
-                ---
-                EOF
+https://wiki.gnome.org/Git/Help/TagUpdates
+---
+EOF
             exit 1
             fi
             ;;
         update)
             cat <<- EOF >&2
-                ---
-                You are trying to replace the tag '$tagname' with a new tag. Please see:
+$GITLAB_ERR_PREFIX
+---
+You are trying to replace the tag '$tagname' with a new tag. Please see:
 
-                  https://wiki.gnome.org/Git/Help/TagUpdates
-                ---
-                EOF
+https://wiki.gnome.org/Git/Help/TagUpdates
+---
+EOF
             exit 1
             ;;
         esac
@@ -258,14 +267,15 @@ check_ref_update() {
     refs/remotes/*)
         # Remote tracking branch
         cat <<- EOF >&2
-            ---
-            You are trying to push the remote tracking branch:
+$GITLAB_ERR_PREFIX
+---
+You are trying to push the remote tracking branch:
 
-              $refname
+  $refname
 
-            to $server.
-            ---
-            EOF
+to $server.
+---
+EOF
         exit 1
         ;;
     refs/notes/*)
@@ -278,10 +288,11 @@ check_ref_update() {
         delete)
             if [ "x$notename" = xcommits ] ; then
             cat <<- EOF >&2
-                ---
-                You are trying to delete the note 'commits'.
-                ---
-                EOF
+$GITLAB_ERR_PREFIX
+---
+You are trying to delete the note 'commits'.
+---
+EOF
             exit 1
             fi
             ;;
@@ -293,13 +304,14 @@ check_ref_update() {
             # allow overriding without having to change the config
             # temporarily.
             cat <<- EOF >&2
-                ---
-                You are trying to update the note '$notename' in a way that is not
-                a fast-forward update. Please see:
-
-                  https://wiki.gnome.org/Git/Help/NonFastForward
-                ---
-                EOF
+$GITLAB_ERR_PREFIX
+---
+You are trying to update the note '$notename' in a way that is not
+a fast-forward update. Please see:
+
+https://wiki.gnome.org/Git/Help/NonFastForward
+---
+EOF
             exit 1
             fi
             ;;
@@ -308,14 +320,15 @@ check_ref_update() {
     *)
         # Something else
         cat <<- EOF >&2
-            ---
-            You are trying to push the ref:
+$GITLAB_ERR_PREFIX
+---
+You are trying to push the ref:
 
-              $refname
+  $refname
 
-            to $server. This is not a branch or tag.
-            ---
-            EOF
+to $server. This is not a branch or tag.
+---
+    EOF
         exit 1
         ;;
     esac


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