Skip to content

Commit 04f8925

Browse files
jonseymourgitster
authored andcommitted
Ensure git ls-tree exits with a non-zero exit code if read_tree_recursive fails.
In the case of a corrupt repository, git ls-tree may report an error but presently it exits with a code of 0. This change uses the return code of read_tree_recursive instead. Improved-by: Jens Lehmann <[email protected]> Signed-off-by: Jon Seymour <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6c1c144 commit 04f8925

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

builtin/ls-tree.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,5 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
173173
tree = parse_tree_indirect(sha1);
174174
if (!tree)
175175
die("not a tree object");
176-
read_tree_recursive(tree, "", 0, 0, &pathspec, show_tree, NULL);
177-
178-
return 0;
176+
return !!read_tree_recursive(tree, "", 0, 0, &pathspec, show_tree, NULL);
179177
}

t/t3103-ls-tree-misc.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ test_expect_success 'setup' '
1616
git commit -m test
1717
'
1818

19-
test_expect_failure 'ls-tree fails with non-zero exit code on broken tree' '
19+
test_expect_success 'ls-tree fails with non-zero exit code on broken tree' '
2020
rm -f .git/objects/5f/cffbd6e4c5c5b8d81f5e9314b20e338e3ffff5 &&
2121
test_must_fail git ls-tree -r HEAD
2222
'

0 commit comments

Comments
 (0)