bundle: fix wrong check of read_header()'s return value & add tests
If read_header() fails, it returns <0, not 0. Further, an open(/dev/null) was not checked for errors. Also, this adds two tests to make sure that the bundle file looks correct, by checking if it has the header has the expected form, and that the pack contains the right amount of objects. Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
Johannes Schindelin committed
Mar 6, 2007 at 22:57 UTC
8315588b59bea45c4b82451cc3ac337fa5c68526
2 files changed
+24
-1
builtin-bundle.c
+3
-1
@@ -404,6 +404,8 @@ static int unbundle(struct bundle_header *header, int bundle_fd,
404
if (verify_bundle(header, 0))
405
return -1;
406
dev_null = open("/dev/null", O_WRONLY);
407
+ if (dev_null < 0)
408
+ return error("Could not open /dev/null");
409
pid = fork_with_pipe(argv_index_pack, &bundle_fd, &dev_null);
410
if (pid < 0)
411
return error("Could not spawn index-pack");
@@ -440,7 +442,7 @@ int cmd_bundle(int argc, const char **argv, const char *prefix)
442
443
memset(&header, 0, sizeof(header));
444
if (strcmp(cmd, "create") &&
443
- !(bundle_fd = read_header(bundle_file, &header)))
445
+ (bundle_fd = read_header(bundle_file, &header)) < 0)
446
return 1;
447
448
if (!strcmp(cmd, "verify")) {
t/t5510-fetch.sh
+21
@@ -90,6 +90,13 @@ test_expect_success 'create bundle 1' '
90
git bundle create bundle1 master^..master
91
'
92
93
+test_expect_success 'header of bundle looks right' '
94
+ head -n 1 "$D"/bundle1 | grep "^#" &&
95
+ head -n 2 "$D"/bundle1 | grep "^-[0-9a-f]\{40\} " &&
96
+ head -n 3 "$D"/bundle1 | grep "^[0-9a-f]\{40\} " &&
97
+ head -n 4 "$D"/bundle1 | grep "^$"
98
+'
99
+
100
test_expect_success 'create bundle 2' '
101
cd "$D" &&
102
git bundle create bundle2 master~2..master
@@ -101,6 +108,20 @@ test_expect_failure 'unbundle 1' '
108
git fetch "$D/bundle1" master:master
109
'
110
111
+test_expect_success 'bundle 1 has only 3 files ' '
112
+ cd "$D" &&
113
+ (
114
+ while read x && test -n "$x"
115
+ do
116
+ :;
117
+ done
118
+ cat
119
+ ) <bundle1 >bundle.pack &&
120
+ git index-pack bundle.pack &&
121
+ verify=$(git verify-pack -v bundle.pack) &&
122
+ test 4 = $(echo "$verify" | wc -l)
123
+'
124
+
125
test_expect_success 'unbundle 2' '
126
cd "$D/bundle" &&
127
git fetch ../bundle2 master:master &&