summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeert Uytterhoeven <geert+renesas@glider.be>2019-08-22 15:24:08 +0200
committerGeert Uytterhoeven <geert+renesas@glider.be>2019-11-25 14:52:45 +0100
commit17f19806f7de23212561c879c0f2b003f3958642 (patch)
treef5976d251a20bfdf4f0c63503ea977e745b37898
parentb0d252d6a4a43a3143b488bba5a61c83e93a1301 (diff)
scripts/pre-commit: Auto-generate keys when needed
Generate unique keys for YAML project files lacking them. There are two minor issues left: 1. Due to the "git add", not only the key is added to the file, but also any other changes that are not yet staged, 2. When doing "git add <file>; git commit <file>", the addition of the key is also left in the unstaged changes as a side effect, so "git diff" still shows that change as uncommitted. More investigation shows this only happens when passing the file name to the "git commit" command. Hence it does not happen when doing "git add <file>; git commit". Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> Tested-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
-rwxr-xr-xscripts/pre-commit.sh17
1 files changed, 16 insertions, 1 deletions
diff --git a/scripts/pre-commit.sh b/scripts/pre-commit.sh
index 38894f4..bc7fb6e 100755
--- a/scripts/pre-commit.sh
+++ b/scripts/pre-commit.sh
@@ -1,5 +1,7 @@
#!/bin/bash
+set -e
+
if git rev-parse --verify HEAD >/dev/null 2>&1
then
base=HEAD
@@ -10,9 +12,22 @@ fi
error=0
-# Validate new/modified YAML project files
for i in $(git diff --cached --name-only --diff-filter=AM $base -- "*yaml" | grep -vF .schema.yaml)
do
+ # Generate unique key if missing
+ if ! grep -q ^key: "$i"
+ then
+ key=$(uuid)
+ while grep -qrw "$key" .
+ do
+ key=$(uuid)
+ done
+ echo "Generated key $key for $i"
+ sed -i "/^team:/akey: $key" "$i"
+ git add "$i"
+ fi
+
+ # Validate new/modified YAML project files
echo -n "Validating $i: "
if ! scripts/validator "$i"
then