Code

merge: use return value of resolve_ref() to determine if HEAD is invalid
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Sat, 17 Sep 2011 11:57:43 +0000 (21:57 +1000)
committerJunio C Hamano <gitster@pobox.com>
Sun, 18 Sep 2011 20:55:56 +0000 (13:55 -0700)
resolve_ref() only updates "head" when it returns non NULL value (it
may update "head" even when returning NULL, but not in all cases).

Because "head" is not initialized before the call, is_null_sha1() is
not enough. Check also resolve_ref() return value.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/merge.c

index a068660d0989a803a871aa6d820e0cc347bbf586..c371484ab6b779d183534a04a57cdb3c190fc9a9 100644 (file)
@@ -1030,7 +1030,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
        branch = resolve_ref("HEAD", head, 0, &flag);
        if (branch && !prefixcmp(branch, "refs/heads/"))
                branch += 11;
-       if (is_null_sha1(head))
+       if (!branch || is_null_sha1(head))
                head_invalid = 1;
 
        git_config(git_merge_config, NULL);