summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4e44ae4)
raw | patch | inline | side by side (parent: 4e44ae4)
author | Lea Wiemann <lewiemann@gmail.com> | |
Mon, 9 Jun 2008 00:02:21 +0000 (02:02 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 9 Jun 2008 20:46:08 +0000 (13:46 -0700) |
Previously, cat-file --batch / --batch-check would silently exit if it
was passed a non-existent SHA1 on stdin. Now it prints "<SHA1>
missing" as in all other cases (and as advertised in the
documentation).
Note that cat-file --batch-check (but not --batch) will still output
"error: unable to find <SHA1>" on stderr if a non-existent SHA1 is
passed, but this does not affect parsing its stdout.
Also, type <= 0 was previously using the potentially uninitialized
type variable (relying on it being 0); it is now being initialized.
Signed-off-by: Lea Wiemann <LeWiemann@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
was passed a non-existent SHA1 on stdin. Now it prints "<SHA1>
missing" as in all other cases (and as advertised in the
documentation).
Note that cat-file --batch-check (but not --batch) will still output
"error: unable to find <SHA1>" on stderr if a non-existent SHA1 is
passed, but this does not affect parsing its stdout.
Also, type <= 0 was previously using the potentially uninitialized
type variable (relying on it being 0); it is now being initialized.
Signed-off-by: Lea Wiemann <LeWiemann@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-cat-file.c | patch | blob | history | |
t/t1006-cat-file.sh | patch | blob | history |
diff --git a/builtin-cat-file.c b/builtin-cat-file.c
index f8b3160668e1eeff3ef9a893459c64992aa53b5b..bd343efae7d6cc6fddef4df5c3433b97bd640d3c 100644 (file)
--- a/builtin-cat-file.c
+++ b/builtin-cat-file.c
static int batch_one_object(const char *obj_name, int print_contents)
{
unsigned char sha1[20];
- enum object_type type;
+ enum object_type type = 0;
unsigned long size;
void *contents = contents;
else
type = sha1_object_info(sha1, &size);
- if (type <= 0)
- return 1;
+ if (type <= 0) {
+ printf("%s missing\n", obj_name);
+ fflush(stdout);
+ return 0;
+ }
printf("%s %s %lu\n", sha1_to_hex(sha1), typename(type), size);
fflush(stdout);
diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh
index 973aef7a8e0949ea381626e5d3b49445f63423ef..d8b7f2ffbcc0427b1ae9d48feb4387f580e81d61 100755 (executable)
--- a/t/t1006-cat-file.sh
+++ b/t/t1006-cat-file.sh
'
done
-test_expect_success "--batch-check for a non-existent object" '
- test "deadbeef missing" = \
- "$(echo_without_newline deadbeef | git cat-file --batch-check)"
+test_expect_success "--batch-check for a non-existent named object" '
+ test "foobar42 missing
+foobar84 missing" = \
+ "$( ( echo foobar42; echo_without_newline foobar84; ) | git cat-file --batch-check)"
+'
+
+test_expect_success "--batch-check for a non-existent hash" '
+ test "0000000000000000000000000000000000000042 missing
+0000000000000000000000000000000000000084 missing" = \
+ "$( ( echo 0000000000000000000000000000000000000042;
+ echo_without_newline 0000000000000000000000000000000000000084; ) \
+ | git cat-file --batch-check)"
+'
+
+test_expect_success "--batch for an existent and a non-existent hash" '
+ test "$tag_sha1 tag $tag_size
+$tag_content
+0000000000000000000000000000000000000000 missing" = \
+ "$( ( echo $tag_sha1;
+ echo_without_newline 0000000000000000000000000000000000000000; ) \
+ | git cat-file --batch)"
'
test_expect_success "--batch-check for an emtpy line" '