Re: [PATCH v3 4/4] last-modified: verify revision argument is a commit-ish
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jan 16, 2026, 18:24 UTC
- Message-ID
- <xmqqh5sl8lg3.fsf@gitster.g>
- In-Reply-To
- <20260116-toon-last-modified-tree-v3-4-e6ade4dc35ab@iotcl.com>
Toon Claes <toon@iotcl.com> writes:
Show 26 quoted lines
> Passing a tree OID to git-last-modified(1) would trigger BUG behavior.
>
> git last-modified HEAD^{tree}
> BUG: builtin/last-modified.c:456: paths remaining beyond boundary in last-modified
>
> Fix this error by verifying the parsed revision is a commit-ish.
>
> 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 0df85be318..5366cedd0f 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 is not a commit-ish"));
> + goto out;
> + }This will do, at least for now, but I tend to prefer to say what the user gave us when we expected a commit, e.g., "commit expected, got a tree".