Skip to content

Commit 64b9db5

Browse files
committed
Merge branch 'js/ls-tree-error' into maint
* js/ls-tree-error: Ensure git ls-tree exits with a non-zero exit code if read_tree_recursive fails. Add a test to check that git ls-tree sets non-zero exit code on error.
2 parents 5480861 + 04f8925 commit 64b9db5

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
3+
test_description='
4+
Miscellaneous tests for git ls-tree.
5+
6+
1. git ls-tree fails in presence of tree damage.
7+
8+
'
9+
10+
. ./test-lib.sh
11+
12+
test_expect_success 'setup' '
13+
mkdir a &&
14+
touch a/one &&
15+
git add a/one &&
16+
git commit -m test
17+
'
18+
19+
test_expect_success 'ls-tree fails with non-zero exit code on broken tree' '
20+
rm -f .git/objects/5f/cffbd6e4c5c5b8d81f5e9314b20e338e3ffff5 &&
21+
test_must_fail git ls-tree -r HEAD
22+
'
23+
24+
test_done

0 commit comments

Comments
 (0)