Fixed segmentation fault that can be triggered using $ git clone --branch $object $repository with object pointing to a non-commit (e.g. a blob). Signed-off-by: Davide Berardi <berardi.dav@xxxxxxxxx> --- builtin/clone.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/builtin/clone.c b/builtin/clone.c index f665b28ccc..6ad2d8fe77 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -720,6 +720,9 @@ static void update_head(const struct ref *our, const struct ref *remote, } else if (our) { struct commit *c = lookup_commit_reference(the_repository, &our->old_oid); + /* Check if --branch specifies a non-commit. */ + if (c == NULL) + die(_("unable to update HEAD (cannot find commit)")); /* --branch specifies a non-branch (i.e. tags), detach HEAD */ update_ref(msg, "HEAD", &c->object.oid, NULL, REF_NO_DEREF, UPDATE_REFS_DIE_ON_ERR); -- 2.23.0