Skip to content

Commit 9a810e1

Browse files
committed
last-modified: verify revision argument is a commit-ish
Passing a non-committish revision to git-last-modified(1) triggers the following BUG: git last-modified HEAD^{tree} BUG: builtin/last-modified.c:456: paths remaining beyond boundary in last-modified Fix this error by ensuring that the given revision peels to a commit. Reported-by: Gusted <[email protected]> Signed-off-by: Toon Claes <[email protected]>
1 parent 8f37827 commit 9a810e1

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

builtin/last-modified.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ static int populate_paths_from_revs(struct last_modified *lm)
150150
goto out;
151151
}
152152

153+
if (!repo_peel_to_type(lm->rev.repo, obj->path, 0, obj->item, OBJ_COMMIT)) {
154+
ret = error(_("revision argument '%s' is a %s, not a commit-ish"), obj->name, type_name(obj->item->type));
155+
goto out;
156+
}
157+
153158
diff_tree_oid(lm->rev.repo->hash_algo->empty_tree,
154159
&obj->item->oid, "", &diffopt);
155160
diff_flush(&diffopt);

t/t8020-last-modified.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ test_expect_success 'setup' '
88
test_commit 1 file &&
99
mkdir a &&
1010
test_commit 2 a/file &&
11+
git tag -mA t2 2 &&
1112
mkdir a/b &&
1213
test_commit 3 a/b/file
1314
'
@@ -51,6 +52,13 @@ test_expect_success 'last-modified recursive' '
5152
EOF
5253
'
5354

55+
test_expect_success 'last-modified on annotated tag' '
56+
check_last_modified t2 <<-\EOF
57+
2 a
58+
1 file
59+
EOF
60+
'
61+
5462
test_expect_success 'last-modified recursive with show-trees' '
5563
check_last_modified -r -t <<-\EOF
5664
3 a/b
@@ -236,4 +244,9 @@ test_expect_success 'last-modified complains about unknown arguments' '
236244
test_grep "unknown last-modified argument: --foo" err
237245
'
238246

247+
test_expect_success 'last-modified expects commit-ish' '
248+
test_must_fail git last-modified HEAD^{tree} 2>err &&
249+
grep "revision argument '"'"'HEAD^{tree}'"'"' is a tree, not a commit-ish" err
250+
'
251+
239252
test_done

0 commit comments

Comments
 (0)