git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bert Wesarg <bert.wesarg@googlemail.com>
To: Petr Baudis <pasky@suse.cz>
To: Petr Baudis <pasky@suse.cz>
Cc: Bert Wesarg <bert.wesarg@googlemail.com>,
	git@vger.kernel.org, martin f krafft <madduck@debian.org>,
	Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>
Subject: [TopGit PATCH] pre-commit: check .top* files in the to-be-commited tree
Date: Tue,  2 Jun 2009 22:40:38 +0200	[thread overview]
Message-ID: <1243975238-4807-1-git-send-email-bert.wesarg@googlemail.com> (raw)

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)

             reply	other threads:[~2009-06-02 20:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-02 20:40 Bert Wesarg [this message]
2009-06-04  5:27 ` [TopGit PATCH] pre-commit: check .top* files in the to-be-commited tree Uwe Kleine-König
2009-06-04 21:29   ` Bert Wesarg
  -- strict thread matches above, loose matches on Subject: below --
2010-10-04 18:54 Bert Wesarg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1243975238-4807-1-git-send-email-bert.wesarg@googlemail.com \
    --to=bert.wesarg@googlemail.com \
    --cc=git@vger.kernel.org \
    --cc=madduck@debian.org \
    --cc=pasky@suse.cz \
    --cc=u.kleine-koenig@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).