git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[TopGit PATCH] pre-commit: check .top* files in the to-be-commited tree

From
Bert Wesarg <bert.wesarg@googlemail.com>
Date
Jun 2, 2009, 20:40 UTC
Message-ID
<1243975238-4807-1-git-send-email-bert.wesarg@googlemail.com>

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>
---
 hooks/pre-commit.sh |   36 +++++++++++++++++++++++++++++++-----
 1 files changed, 31 insertions(+), 5 deletions(-)
diff --git a/hooks/pre-commit.sh b/hooks/pre-commit.sh
index 9d677e9..7f66c75 100644
--- a/hooks/pre-commit.sh
+++ b/hooks/pre-commit.sh
@@ -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=$1
+	local file=$2
+
+	local 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
+	local type=$2
+	local 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"
+}
+
+# I suspect this can't fail, but who knows
+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
-- 
tg: (b725fc9..) bw/pre-commit-check-.top-files (depends on: master)
Next: Uwe Kleine-König
Message 1 of 3 in “pre-commit: check .top* files in the to-be-commited tree”
  1. pre-commit: check .top* files in the to-be-commited treeBert Wesarg, Jun 2, 2009
  2. Uwe Kleine-KönigJun 4, 2009
  3. Bert WesargJun 4, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.