replay: die when --onto does not peel to a commit
The `peel_committish()` function calls `repo_peel_to_type()` to convert the given object to a commit, but does not check the return value. When the object exists but cannot be peeled to a commit (e.g., a tree or blob OID is passed as --onto), the return value is NULL. Add an explicit NULL check and die with a descriptive message in that case. Pointed out by Coverity. Assisted-by: Claude Opus 4.6 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Jul 10, 2026 at 11:39 UTC
e87d701dc69a6b194f223f2405102cae4c4af03b
1 file changed
+6
-2
replay.c
+6
-2
index da531d5bc6..b38cd5efe4 100644
--- a/replay.c
+++ b/replay.c
@@ -36,12 +36,16 @@ static struct commit *peel_committish(struct repository *repo,
{
struct object *obj;
struct object_id oid;
+ struct commit *commit;
if (repo_get_oid(repo, name, &oid))
die(_("'%s' is not a valid commit-ish for %s"), name, mode);
obj = parse_object_or_die(repo, &oid, name);
- return (struct commit *)repo_peel_to_type(repo, name, 0, obj,
- OBJ_COMMIT);
+ commit = (struct commit *)repo_peel_to_type(repo, name, 0, obj,
+ OBJ_COMMIT);
+ if (!commit)
+ die(_("'%s' does not point to a commit for %s"), name, mode);
+ return commit;
}
static char *get_author(const char *message)