[PATCH v5 4/4] last-modified: verify revision argument is a commit-ish
- From
Toon Claes <toon@iotcl.com>
- Date
- Jan 27, 2026, 13:26 UTC
- Message-ID
- <20260127-toon-last-modified-tree-v5-4-38d18a0956d4@iotcl.com>
- In-Reply-To
- <20260127-toon-last-modified-tree-v5-0-38d18a0956d4@iotcl.com>
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-modifiedFix this error by ensuring that the given revision peels to a commit.
Reported-by: Gusted <gusted@codeberg.org> Signed-off-by: Toon Claes <toon@iotcl.com> --- builtin/last-modified.c | 5 +++++ t/t8020-last-modified.sh | 13 +++++++++++++ 2 files changed, 18 insertions(+)
diff --git a/builtin/last-modified.c b/builtin/last-modified.c index e02ec8428b..d0944673f0 100644 --- a/builtin/last-modified.c +++ b/builtin/last-modified.c @@ -150,6 +150,11 @@ static int populate_paths_from_revs(struct last_modified *lm) goto out; } + if (!repo_peel_to_type(lm->rev.repo, obj->path, 0, obj->item, OBJ_COMMIT)) { + ret = error(_("revision argument '%s' is a %s, not a commit-ish"), obj->name, type_name(obj->item->type)); + goto out; + } + diff_tree_oid(lm->rev.repo->hash_algo->empty_tree, &obj->item->oid, "", &diffopt); diff_flush(&diffopt); diff --git a/t/t8020-last-modified.sh b/t/t8020-last-modified.sh index d1aad12319..6024e8bd60 100755 --- a/t/t8020-last-modified.sh +++ b/t/t8020-last-modified.sh @@ -8,6 +8,7 @@ test_expect_success 'setup' ' test_commit 1 file && mkdir a && test_commit 2 a/file && + git tag -mA t2 2 && mkdir a/b && test_commit 3 a/b/file ' @@ -51,6 +52,13 @@ test_expect_success 'last-modified recursive' ' EOF ' +test_expect_success 'last-modified on annotated tag' ' + check_last_modified t2 <<-\EOF + 2 a + 1 file + EOF +' + test_expect_success 'last-modified recursive with show-trees' ' check_last_modified -r -t <<-\EOF 3 a/b @@ -236,4 +244,9 @@ test_expect_success 'last-modified complains about unknown arguments' ' test_grep "unknown last-modified argument: --foo" err ' +test_expect_success 'last-modified expects commit-ish' ' + test_must_fail git last-modified HEAD^{tree} 2>err && + grep "revision argument '"'"'HEAD^{tree}'"'"' is a tree, not a commit-ish" err +' + test_done
-- 2.53.0.rc1.267.g6e3a78c723