From: "Brian C. Lane" bcl@redhat.com
--- scripts/githooks/commit-msg | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-)
diff --git a/scripts/githooks/commit-msg b/scripts/githooks/commit-msg index a360dbb..aa3a93e 100755 --- a/scripts/githooks/commit-msg +++ b/scripts/githooks/commit-msg @@ -15,18 +15,20 @@ # This example catches duplicate Signed-off-by lines.
test "" = "$(grep '^Signed-off-by: ' "$1" | - sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || { - echo >&2 Duplicate Signed-off-by lines. - exit 1 + sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || { + echo >&2 Duplicate Signed-off-by lines. + exit 1 }
# Make sure commits on RHEL branches reference RHEL bugs. RETVAL=0
-git branch | grep ^* | cut -c3- | grep -q ^rhel -if [ $? -eq 1 ]; then +branch_name=$(git branch | grep ^* | cut -c3-) +branch_pattern="^rhel([[:digit:]])-branch" +if [[ ! "$branch_name" =~ $branch_pattern ]]; then exit ${RETVAL} fi +RELEASE=${BASH_REMATCH[1]}
if [ -f "${HOME}/.rhbzauth" ]; then . "${HOME}/.rhbzauth" @@ -51,6 +53,16 @@ else ${bzcmd} login fi
+bz_has_ack() { + bug=$1 + flags=$(${bzcmd} query --bug_id=${bug} --outputformat="%{flags}") + + ack_pattern="rhel-${RELEASE}.[[:digit:]]+.[[:digit:]]++" + if [[ ! "$flags" =~ $ack_pattern ]]; then + echo "*** BZ ${bug} is missing acks: ${flags}" + fi +} + summary="$(head -n 1 ${1})" for word in ${summary} ; do echo "${word}" | grep -q -E "^.*(#[0-9]+).*" @@ -61,6 +73,7 @@ for word in ${summary} ; do echo "*** BZ ${bug} is not a RHEL bug." >&2 RETVAL=1 fi + bz_has_ack ${bug} fi done
@@ -75,6 +88,7 @@ if [ ${last} -gt 0 ]; then echo "*** BZ ${bug} is not a RHEL bug." >&2 RETVAL=1 fi + bz_has_ack ${bug} done fi
On Mon, 2013-09-16 at 12:17 -0700, Brian C. Lane wrote:
From: "Brian C. Lane" bcl@redhat.com
scripts/githooks/commit-msg | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-)
diff --git a/scripts/githooks/commit-msg b/scripts/githooks/commit-msg index a360dbb..aa3a93e 100755 --- a/scripts/githooks/commit-msg +++ b/scripts/githooks/commit-msg @@ -15,18 +15,20 @@ # This example catches duplicate Signed-off-by lines.
test "" = "$(grep '^Signed-off-by: ' "$1" |
sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || {- echo >&2 Duplicate Signed-off-by lines.
- exit 1
- sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || {
- echo >&2 Duplicate Signed-off-by lines.
- exit 1
}
# Make sure commits on RHEL branches reference RHEL bugs. RETVAL=0
-git branch | grep ^* | cut -c3- | grep -q ^rhel -if [ $? -eq 1 ]; then +branch_name=$(git branch | grep ^* | cut -c3-) +branch_pattern="^rhel([[:digit:]])-branch" +if [[ ! "$branch_name" =~ $branch_pattern ]]; then exit ${RETVAL} fi +RELEASE=${BASH_REMATCH[1]}
if [ -f "${HOME}/.rhbzauth" ]; then . "${HOME}/.rhbzauth" @@ -51,6 +53,16 @@ else ${bzcmd} login fi
+bz_has_ack() {
- bug=$1
- flags=$(${bzcmd} query --bug_id=${bug} --outputformat="%{flags}")
- ack_pattern="rhel-${RELEASE}.[[:digit:]]+.[[:digit:]]++"
- if [[ ! "$flags" =~ $ack_pattern ]]; then
echo "*** BZ ${bug} is missing acks: ${flags}"- fi
+}
summary="$(head -n 1 ${1})" for word in ${summary} ; do echo "${word}" | grep -q -E "^.*(#[0-9]+).*" @@ -61,6 +73,7 @@ for word in ${summary} ; do echo "*** BZ ${bug} is not a RHEL bug." >&2 RETVAL=1 fi
fibz_has_ack ${bug}done
@@ -75,6 +88,7 @@ if [ ${last} -gt 0 ]; then echo "*** BZ ${bug} is not a RHEL bug." >&2 RETVAL=1 fi
donebz_has_ack ${bug}fi
ACK.
From: "Brian C. Lane" bcl@redhat.com
Previous patch wasn't fatal at all, and only checked for rhelX-branch. The commit-msg hook doesn't run when cherry-picking which is usually how I move things over to the primary branch after acks are granted.
This makes commits on non -branch branches starting with rhelX- just a warning. And if you do happen to commit on the primary it will be fatal.
I haven't figured out a way to hook cherry-picks yet, so this will have to do for now.
(note this will be squashed with the previous and this commentary removed) --- scripts/githooks/commit-msg | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/scripts/githooks/commit-msg b/scripts/githooks/commit-msg index aa3a93e..8fa2f8d 100755 --- a/scripts/githooks/commit-msg +++ b/scripts/githooks/commit-msg @@ -24,12 +24,21 @@ test "" = "$(grep '^Signed-off-by: ' "$1" | RETVAL=0
branch_name=$(git branch | grep ^* | cut -c3-) -branch_pattern="^rhel([[:digit:]])-branch" +branch_pattern="^rhel([[:digit:]])-(.*)" if [[ ! "$branch_name" =~ $branch_pattern ]]; then exit ${RETVAL} fi RELEASE=${BASH_REMATCH[1]}
+# Is this a local branch, or the primary branch? +if [ "${BASH_REMATCH[2]}" == "branch" ]; then + # Make a missing ack block the commit + ACK_FATAL=1 +else + # Missing acks are just warnings + ACK_FATAL=0 +fi + if [ -f "${HOME}/.rhbzauth" ]; then . "${HOME}/.rhbzauth" fi @@ -53,6 +62,8 @@ else ${bzcmd} login fi
+# Check the bz to see if it has an ack for this release. If the branch is +# a local branch, just warn. If it is the primary branch, block the commit. bz_has_ack() { bug=$1 flags=$(${bzcmd} query --bug_id=${bug} --outputformat="%{flags}") @@ -60,6 +71,10 @@ bz_has_ack() { ack_pattern="rhel-${RELEASE}.[[:digit:]]+.[[:digit:]]++" if [[ ! "$flags" =~ $ack_pattern ]]; then echo "*** BZ ${bug} is missing acks: ${flags}" + + if [ $ACK_FATAL -eq 1 ]; then + RETVAL=1 + fi fi }
On Tue, 2013-09-17 at 09:37 -0700, Brian C. Lane wrote:
From: "Brian C. Lane" bcl@redhat.com
Previous patch wasn't fatal at all, and only checked for rhelX-branch. The commit-msg hook doesn't run when cherry-picking which is usually how I move things over to the primary branch after acks are granted.
This makes commits on non -branch branches starting with rhelX- just a warning. And if you do happen to commit on the primary it will be fatal.
I haven't figured out a way to hook cherry-picks yet, so this will have to do for now.
(note this will be squashed with the previous and this commentary removed)
scripts/githooks/commit-msg | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/scripts/githooks/commit-msg b/scripts/githooks/commit-msg index aa3a93e..8fa2f8d 100755 --- a/scripts/githooks/commit-msg +++ b/scripts/githooks/commit-msg @@ -24,12 +24,21 @@ test "" = "$(grep '^Signed-off-by: ' "$1" | RETVAL=0
branch_name=$(git branch | grep ^* | cut -c3-) -branch_pattern="^rhel([[:digit:]])-branch" +branch_pattern="^rhel([[:digit:]])-(.*)" if [[ ! "$branch_name" =~ $branch_pattern ]]; then exit ${RETVAL} fi RELEASE=${BASH_REMATCH[1]}
+# Is this a local branch, or the primary branch? +if [ "${BASH_REMATCH[2]}" == "branch" ]; then
- # Make a missing ack block the commit
- ACK_FATAL=1
+else
- # Missing acks are just warnings
- ACK_FATAL=0
+fi
if [ -f "${HOME}/.rhbzauth" ]; then . "${HOME}/.rhbzauth" fi @@ -53,6 +62,8 @@ else ${bzcmd} login fi
+# Check the bz to see if it has an ack for this release. If the branch is +# a local branch, just warn. If it is the primary branch, block the commit. bz_has_ack() { bug=$1 flags=$(${bzcmd} query --bug_id=${bug} --outputformat="%{flags}") @@ -60,6 +71,10 @@ bz_has_ack() { ack_pattern="rhel-${RELEASE}.[[:digit:]]+.[[:digit:]]++" if [[ ! "$flags" =~ $ack_pattern ]]; then echo "*** BZ ${bug} is missing acks: ${flags}"
if [ $ACK_FATAL -eq 1 ]; thenRETVAL=1 fifi}
Nice improvement, ACK.
anaconda-patches@lists.fedorahosted.org