chiark / gitweb /
hooks/pre-commit: check .top* files in the to-be-commited tree
authorBert Wesarg <bert.wesarg@googlemail.com>
Mon, 4 Oct 2010 18:54:57 +0000 (20:54 +0200)
committerUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Tue, 5 Oct 2010 06:58:29 +0000 (08:58 +0200)
We currently check fo these files only in the working tree. But we should check
what would be commited. We use write-tree to be able to utilize ls-tree and
check the result.

Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
hooks/pre-commit.sh

index 9d677e91279a4275e284fd94077e5a4a90a366d1..8ac913f6479d86af2a64e2dea1e0aff39f347cd4 100644 (file)
@@ -29,10 +29,36 @@ else
        exit 0;
 fi
 
-# TODO: check the index, not the working copy
-[ -s "$root_dir/.topdeps" ] ||
-       die ".topdeps is missing"
-[ -s "$root_dir/.topmsg" ] ||
-       die ".topmsg is missing"
+check_topfile()
+{
+       local tree file ls_line type size
+       tree=$1
+       file=$2
+
+       ls_line="$(git ls-tree --long "$tree" "$file")" ||
+               die "Can't ls tree for $file"
+
+       [ -n "$ls_line" ] ||
+               die "$file is missing"
+
+       # check for type and size
+       set -- $ls_line
+       type=$2
+       size=$4
+
+       # check file is of type blob (file)
+       [ "x$type" = "xblob" ] ||
+               die "$file is not a file"
+
+       # check for positive size
+       [ "$size" -gt 0 ] ||
+               die "$file has empty size"
+}
+
+tree=$(git write-tree) ||
+       die "Can't write tree"
+
+check_topfile "$tree" ".topdeps"
+check_topfile "$tree" ".topmsg"
 
 # TODO: Verify .topdeps for valid branch names and against cycles