From patchwork Thu Mar 26 13:48:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3327 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BDA5260410 for ; Thu, 26 Mar 2020 14:48:30 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="HVdPGfQ5"; dkim-atps=neutral Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3BA312DC for ; Thu, 26 Mar 2020 14:48:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1585230510; bh=bo1i5WpCbTj7GE5wn7X+qe45dwjm4L+rbfHBJ4XBaak=; h=From:To:Subject:Date:From; b=HVdPGfQ5nGspE8/8isQJlbkWAnv9TxlRMGBvBPjaYY8FCHEMGoM6H+P5E//X5rAZ4 DsU74U7N0Z1HyUOS0oGoAagwWgAVIrmDfwu0QNMAIkGClvKzoizaHmsi9ht4GQgpsw s+5gZHfV/qayocpKi1T6oaohJ+EPCgIrZSMtuwNM= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Thu, 26 Mar 2020 15:48:21 +0200 Message-Id: <20200326134821.8542-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2] utils: hooks: Add pre-push commit hook X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Mar 2020 13:48:31 -0000 Add a pre-push commit hooks to prevent unintentional push of patches containing local changelogs to the master branch. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- Changes since v1: - Fix shellcheck issues - Rewrite the description in the top comment - Remove dead or useless code --- utils/hooks/pre-push | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 utils/hooks/pre-push diff --git a/utils/hooks/pre-push b/utils/hooks/pre-push new file mode 100755 index 000000000000..099441b82ea6 --- /dev/null +++ b/utils/hooks/pre-push @@ -0,0 +1,43 @@ +#!/bin/sh + +# A hook script to prevent pushing unsuitable commits to the master branch. +# Unsuitable commits are commits that contain a local changelog below a '---' +# line. The criteria may get extended later. +# +# Information about the commits which are being pushed is supplied as lines to +# the standard input in the form: +# +# + +z40=0000000000000000000000000000000000000000 + +while read -r local_ref local_sha remote_ref remote_sha +do + if [ "$remote_ref" != refs/heads/master ] + then + continue + fi + + # The remote master branch should never get deleted by this push, so we + # can assume that local_sha is not 0's. We may however be creating the + # remote branch, when pushing to a new empty repository for instance. + if [ "$remote_sha" = $z40 ] + then + # New branch, examine all commits + range="$local_sha" + else + # Update to existing branch, examine new commits + range="$remote_sha..$local_sha" + fi + + # Find invalid commits. + commit=$(git rev-list -n 1 --grep '^---' "$range") + if [ -n "$commit" ] + then + echo >&2 "Found local changelog in $local_ref, not pushing" + echo >&2 "Check commit $commit" + exit 1 + fi +done + +exit 0