summaryrefslogtreecommitdiffstats
path: root/util/git-hooks/pre-push
diff options
context:
space:
mode:
authorStefan Tauner <stefan.tauner@alumni.tuwien.ac.at>2016-11-27 17:45:49 +0100
committerStefan Tauner <stefan.tauner@alumni.tuwien.ac.at>2016-12-04 19:40:06 +0100
commitf5dd7ce11b65ffd6ead214b4b4cbe90f3eb110dd (patch)
tree4518299cac54e260f4310de1dad92468e3eaa2a2 /util/git-hooks/pre-push
parent40ba6fd0486b9845a951dbe042b1121687353c1a (diff)
downloadast2050-flashrom-f5dd7ce11b65ffd6ead214b4b4cbe90f3eb110dd.zip
ast2050-flashrom-f5dd7ce11b65ffd6ead214b4b4cbe90f3eb110dd.tar.gz
Convert flashrom to git
- Drop support for Subversion in the getrevision script and Makefile. - Add .gitignore and .gitattributes file (the latter to limit exports). - Restore modification dates of the exported files from the SCM. - Stop exporting SCM log dumps to CHANGELOG. This makes no sense. - Remove djgpp-dos target (it is not different to other x-compilations). - Do not export the pre-"compiled" manpage. It can be generated like anything else from the code dump when we export the respective variable. The latter is added with this change. - Add some initial client-side git hooks * When committing check for obvious stuff you never want anyway: - white space errors - duplicate sign-offs * When pushing to the upstream repository check mandatory rules: - existing signoffs and acks in all new commits - no deletions or creation of branches - do not rewrite history of the precious branches, even if forced - Change version string of flashrom as follows. Previously, we included the last stable version according to a hard- coded string in the Makefile and appended the subversion revision number. With this patch the version string includes the last reachable git tag, number of commits since said tag in the upstream branches (if any), the name of said upstream branch, number of commits since that branch (if any), and the shortened git hash. In case there are uncommitted changes a "-dirty" indicator is also added. The case of unknown versions is explicitly handled in getrevision instead of simply appending "-unknown" to a hardcoded release number. The version information is either taken from an existing git remote pointing to an upstream repository (or a known mirror), or if that is not available - with the user's consent - a shadow copy is fetched from the upstream repo that is updated on every build (usually takes less than a second). In the following some examples of the version string changes are shown. Basically we print the distance to the last known upstream tag, which comprises any upstream commits since that tag as well as local commits on top of that. Additionally we handle upstream's stable and staging branches specially. Old output: flashrom v0.9.7-r1716 on Linux 3.8.0-6-generic (x86_64) New output variants: Build of the 0.9.99 release without any changes: flashrom v0.9.99-e4f6643 on Linux 3.13.0-76-generic (x86_64) 5 commits since last tag in upstream's stable branch: flashrom v0.9.99-5-stable-e4f6643-dirty on Linux 3.13.0-76-generic (x86_64) 3 commits since last tag in upstream's staging branch and 4 local commits on top of that: flashrom v0.9.99-3-staging-4-e4f6643 on Linux 3.13.0-76-generic (x86_64) 3 commits since last tag in upstream's staging branch and 4 local commits on top of that, and some local uncommitted changes too: flashrom v0.9.99-3-staging-4-e4f6643-dirty on Linux 3.13.0-76-generic (x86_64) 3 commits since the last tag in an unrelated upstream branch (e.g., a stable release *branch* such as 0.9.99.x) or local branch: flashrom v0.9.99-3-e4f6643 on Linux 3.13.0-76-generic (x86_64) No tags reachable from current commit (generic git fallback): flashrom d95935a version on Linux 3.13.0-76-generic (x86_64) Not in a repository: flashrom unknown version on Linux 3.13.0-76-generic (x86_64) Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at> Acked-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at>
Diffstat (limited to 'util/git-hooks/pre-push')
-rwxr-xr-xutil/git-hooks/pre-push74
1 files changed, 74 insertions, 0 deletions
diff --git a/util/git-hooks/pre-push b/util/git-hooks/pre-push
new file mode 100755
index 0000000..b7e34ee
--- /dev/null
+++ b/util/git-hooks/pre-push
@@ -0,0 +1,74 @@
+#!/bin/sh
+
+# A hook script to verify what is about to be pushed. Called by "git
+# push" after it has checked the remote status, but before anything has been
+# pushed. If this script exits with a non-zero status nothing will be pushed.
+#
+# This hook is called with the following parameters:
+#
+# $1 -- Name of the remote to which the push is being done
+# $2 -- URL to which the push is being done
+#
+# If pushing without using a named remote those arguments will be equal.
+#
+# Information about the commits which are being pushed is supplied as lines to
+# the standard input in the form:
+#
+# <local ref> <local sha1> <remote ref> <remote sha1>
+
+remote="$1"
+url="$2"
+
+zero=0000000000000000000000000000000000000000
+
+upstream_pattern="github\.com.flashrom/flashrom(\.git)?|flashrom\.org.git/flashrom(\.git)?"
+precious_branches=( stable staging )
+
+# Only care about the upstream repository
+if echo "$url" | grep -q -v -E "$upstream_pattern" ; then
+ exit 0
+fi
+
+while read local_ref local_sha remote_ref remote_sha ; do
+ if [ "$remote_ref" != "refs/heads/staging" -a "$remote_ref" != "refs/heads/stable" ]; then
+ echo "Feature branches not allowed ($remote_ref)." >&2
+ exit 1
+ fi
+
+ if [ "$local_sha" = $zero ]; then
+ echo "Deletion of branches is prohibited." >&2
+ exit 1
+ else
+ if [ "$remote_sha" = "$zero" ]; then
+ echo "No new branches allowed." >&2
+ exit 1
+ else
+ range="$remote_sha..$local_sha"
+ fi
+
+ # Check for Signed-off-by and Acked-by
+ commit=$(git rev-list -n 1 --all-match --invert-grep -E \
+ --grep '^Signed-off-by: .+ <.+@.+\..+>$' --grep '^Acked-by: .+ <.+@.+\..+>$' "$range")
+ if [ -n "$commit" ]; then
+ echo "No Signoff or Ack found in commit $local_sha in $local_ref, not pushing." >&2
+ exit 1
+ fi
+
+ # Make _really_ sure we do not rewrite precious history
+ for lbranch in "${precious_branches[@]}"; do
+ if [ "$remote_ref" = "refs/heads/$lbranch" ]; then
+ nonreachable=$(git rev-list $remote_sha ^$local_sha)
+ if [ -n "$nonreachable" ]; then
+ echo "Only fast-forward pushes are allowed on $lbranch." >&2
+ echo "$nonreachable is not included in $remote_sha while pusing to $remote_ref" >&2
+ exit 1
+ fi
+ fi
+ done
+
+ # FIXME: check commit log format (subject without full stop at the end etc).
+ # FIXME: do buildbot checks if authorized?
+ fi
+done
+
+exit 0
OpenPOWER on IntegriCloud