From patchwork Thu Jul 12 09:49:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell Currey X-Patchwork-Id: 942879 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41RBCm5kB8z9rxs for ; Thu, 12 Jul 2018 19:56:20 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=russell.cc Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="BgusDcOJ"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41RBCm3jgNzF35c for ; Thu, 12 Jul 2018 19:56:20 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=russell.cc Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="BgusDcOJ"; dkim-atps=neutral X-Original-To: snowpatch@lists.ozlabs.org Delivered-To: snowpatch@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=russell.cc (client-ip=64.147.123.20; helo=wout4-smtp.messagingengine.com; envelope-from=ruscur@russell.cc; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=russell.cc Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="BgusDcOJ"; dkim-atps=neutral Received: from wout4-smtp.messagingengine.com (wout4-smtp.messagingengine.com [64.147.123.20]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41RBCZ1tQ2zF35Q for ; Thu, 12 Jul 2018 19:56:10 +1000 (AEST) Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 17A50305; Thu, 12 Jul 2018 05:50:12 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Thu, 12 Jul 2018 05:50:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=OD0y0tdwdKzfIRh/oVz8wyu9v5F7yvYWkgLRB0paTg4=; b=BgusDcOJ 8jqZA5sPjxMpNBxX86G9XaMrfgFiJDgcK94iF5B/lh8czcgbCzPw4oevMF4KcKEi jpb6Gl4qQMWLzNaCCceVbw1PvJiP292nZ2cs649+1frKYC9fUPK8u7laFPlSnMkx R+g0nRbVKlDklpmvju/Y9d2rn6bC+DEdoWEJ2qvFGk86A6a8ae6rxcvMqa6N88V0 frmFopTjWzTdgC/rF1okLdomUd9LVl6FIoZTL/CyswRno2USryyhOr5+keiGV1hu fqUyPBV7P8Sov1TJIlJLCQ7Au2UBi/12ojz4IXE5cGjs5iJ3S85phA1PLJDIanfi 3xx4xqoQ35GSrQ== X-ME-Proxy: X-ME-Sender: Received: from snap.au.ibm.com (unknown [122.99.82.10]) by mail.messagingengine.com (Postfix) with ESMTPA id 49AFF10261; Thu, 12 Jul 2018 05:50:10 -0400 (EDT) From: Russell Currey To: snowpatch@lists.ozlabs.org Date: Thu, 12 Jul 2018 19:49:45 +1000 Message-Id: <20180712094945.8368-4-ruscur@russell.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180712094945.8368-1-ruscur@russell.cc> References: <20180712094945.8368-1-ruscur@russell.cc> Subject: [snowpatch] [PATCH 4/4] Add script to set up running rustfmt on commit X-BeenThere: snowpatch@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Continuous Integration for patch-based workflows List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Russell Currey MIME-Version: 1.0 Errors-To: snowpatch-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "snowpatch" Signed-off-by: Russell Currey --- setup_rustfmt_hook.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 setup_rustfmt_hook.sh diff --git a/setup_rustfmt_hook.sh b/setup_rustfmt_hook.sh new file mode 100755 index 0000000..76a8932 --- /dev/null +++ b/setup_rustfmt_hook.sh @@ -0,0 +1,31 @@ +#!/bin/sh +rustup component add rustfmt-preview + +rustfmt_path=`which rustfmt` +echo "#!/bin/bash +declare -a rust_files=() +files=\$(git diff-index --name-only HEAD) +echo 'Formatting source files' +for file in \$files; do + if [ ! -f \"\${file}\" ]; then + continue + fi + if [[ \"\${file}\" == *.rs ]]; then + rust_files+=(\"\${file}\") + fi +done +if [ \${#rust_files[@]} -ne 0 ]; then + $rustfmt_path \${rust_files[@]} & +fi +wait +changed_files=(\"\${rust_files[@]}\" \"\${cpp_files[@]}\") +if [ \${#changed_files[@]} -ne 0 ]; then + git add \${changed_files[@]} + echo \"Formatting done, changed files: \${changed_files[@]}\" +else + echo \"No changes, formatting skipped\" +fi" > .git/hooks/pre-commit + +chmod +x .git/hooks/pre-commit + +echo "Hooks updated"