* [TopGit PATCH] pre-commit: check .top* files in the to-be-commited tree
@ 2010-10-04 18:54 Bert Wesarg
0 siblings, 0 replies; 4+ messages in thread
From: Bert Wesarg @ 2010-10-04 18:54 UTC (permalink / raw)
To: Uwe Kleine-Koenig, Uwe Kleine-Koenig
Cc: git, pasky, martin f krafft, Bert Wesarg, martin f krafft
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 hooks/pre-commit.sh
--- 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: (ff59ac7..) bw/pre-commit-check-.top-files (depends on: master)
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [TopGit PATCH] pre-commit: check .top* files in the to-be-commited tree
@ 2009-06-02 20:40 Bert Wesarg
2009-06-04 5:27 ` Uwe Kleine-König
0 siblings, 1 reply; 4+ messages in thread
From: Bert Wesarg @ 2009-06-02 20:40 UTC (permalink / raw)
To: Petr Baudis, Petr Baudis
Cc: Bert Wesarg, git, martin f krafft, Uwe Kleine-Koenig
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)
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [TopGit PATCH] pre-commit: check .top* files in the to-be-commited tree
2009-06-02 20:40 Bert Wesarg
@ 2009-06-04 5:27 ` Uwe Kleine-König
2009-06-04 21:29 ` Bert Wesarg
0 siblings, 1 reply; 4+ messages in thread
From: Uwe Kleine-König @ 2009-06-04 5:27 UTC (permalink / raw)
To: Bert Wesarg; +Cc: Petr Baudis, git, martin f krafft
Hi Bert,
On Tue, Jun 02, 2009 at 10:40:38PM +0200, Bert Wesarg wrote:
> 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.
<nitpick> I prefer not speaking about "us" in the commit log. Better
use passive voice. </nitpick> So what about:
The pre-commit hook used to check that the working copy has the .top*
files. Instead of that assert that the tree that is about to be
commited has these files.
> +# I suspect this can't fail, but who knows
> +tree=$(git write-tree) ||
> + die "Can't write tree"
Actually you don't need to write the tree. You can use:
git cat-file -t :0:.topdeps
-> blob
git cat-file blob :0:.topdeps | grep .
Up to now I only shortly looked at your patches, but they seem to be OK.
I hope I get around to push the changes later today.
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | http://www.pengutronix.de/ |
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [TopGit PATCH] pre-commit: check .top* files in the to-be-commited tree
2009-06-04 5:27 ` Uwe Kleine-König
@ 2009-06-04 21:29 ` Bert Wesarg
0 siblings, 0 replies; 4+ messages in thread
From: Bert Wesarg @ 2009-06-04 21:29 UTC (permalink / raw)
To: Uwe Kleine-König; +Cc: Petr Baudis, git, martin f krafft
2009/6/4 Uwe Kleine-König <u.kleine-koenig@pengutronix.de>:
> Hi Bert,
Hi Uwe,
>
> On Tue, Jun 02, 2009 at 10:40:38PM +0200, Bert Wesarg wrote:
>> 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.
> <nitpick> I prefer not speaking about "us" in the commit log. Better
> use passive voice. </nitpick> So what about:
>
> The pre-commit hook used to check that the working copy has the .top*
> files. Instead of that assert that the tree that is about to be
> commited has these files.
Yes, thats right, Your message is nice, you can use it for the commit.
>
>> +# I suspect this can't fail, but who knows
>> +tree=$(git write-tree) ||
>> + die "Can't write tree"
> Actually you don't need to write the tree. You can use:
>
> git cat-file -t :0:.topdeps
> -> blob
>
> git cat-file blob :0:.topdeps | grep .
Hmm, not very nice:
$ git init
Initialized empty Git repository in /home/bertw/tmp/has-file/.git/
$ touch .topdeps
$ git add .topdeps
$ git commit -m.topdeps
[master (root-commit) 8193982] .topdeps
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 .topdeps
$ git rm .topdeps
rm '.topdeps'
$ git cat-file -t :0:.topdeps
fatal: Not a valid object name :0:.topdeps
$ echo $?
128
$ git cat-file blob :0:.topdeps | grep .
fatal: Not a valid object name :0:.topdeps
$ echo $?
1
My proposal:
$ git ls-tree --long "$(git write-tree)" .topdeps
$ echo $?
0
Here I know, that all git commands don't die(), they all succeed. The
.topdeps file, I'm looking for, is not in the tree, i.e. empty output.
Bert
> Best regards
> Uwe
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-10-04 18:55 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-04 18:54 [TopGit PATCH] pre-commit: check .top* files in the to-be-commited tree Bert Wesarg
-- strict thread matches above, loose matches on Subject: below --
2009-06-02 20:40 Bert Wesarg
2009-06-04 5:27 ` Uwe Kleine-König
2009-06-04 21:29 ` Bert Wesarg
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).