{"thread":{"id":"4063","subject":"Bad error message","startedAt":"2006-05-04T23:57:26Z","lastAt":"2006-05-05T00:20:47Z","messageCount":2,"participants":["Robin Rosenberg (list subscriber)","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"19533","messageId":"200605041957.26194.robin.rosenberg.lists@dewire.com","threadId":"4063","inReplyTo":null,"subject":"Bad error message","fromName":"Robin Rosenberg (list subscriber)","fromEmail":"robin.rosenberg.lists@dewire.com","sentAt":"2006-05-04T23:57:26Z","receivedAt":"2006-05-04T23:57:26Z","isPatch":false,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"Hi, \n\nWhile playing with git I got the following \"impossible\" error message:\n\n$ git commit --amend\nfatal: Ref HEAD is at 3cec3036287d6b24f7ad7f724f8bb9d4032fb1a3 but expected \n3cec3036287d6b24f7ad7f724f8bb9d4032fb1a3\n\nSince impossible things happen rarely, I was somewhat puzzled and it turned \nout not to be so impossible after all, but a rather typical C bug. Since I \nfixed my working directory using git-reset, I'm not sure how to verify the \ncode (suggestions welcome), but I'm not sure if that's important since the \ncode being replaced by  this patch probably wasn't tested either. :/\n\nMaybe someone could explain what might have been wrong with my work space (git\nstatus turned up nothing wrong or missing).\n\n-- robin\n\n--- git-1.3.1.orig/update-ref.c 2006-04-25 08:07:54.000000000 +0200\n+++ git-1.3.1/update-ref.c      2006-05-04 16:30:04.000000000 +0200\n@@ -43,8 +43,13 @@\n                die(\"No such ref: %s\", refname);\n\n        if (oldval) {\n-               if (memcmp(currsha1, oldsha1, 20))\n-                       die(\"Ref %s is at %s but expected %s\", refname, sha1_to_hex(currsha1), sha1_to_hex(oldsha1));\n+               if (memcmp(currsha1, oldsha1, 20)) {\n+                       char sha1str1[41];\n+                       char sha1str2[41];\n+                       strcpy(sha1str1, sha1_to_hex(currsha1));\n+                       strcpy(sha1str2, sha1_to_hex(oldsha1));\n+                       die(\"Ref %s is at %s but expected %s\", refname, sha1str1, sha1str2);\n+               }\n                /* Nothing to do? */\n                if (!memcmp(oldsha1, sha1, 20))\n                        exit(0);\n"},{"id":"19535","messageId":"7vac9x2ug0.fsf@assigned-by-dhcp.cox.net","threadId":"4063","inReplyTo":"200605041957.26194.robin.rosenberg.lists@dewire.com","subject":"Re: Bad error message","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-05-05T00:20:47Z","receivedAt":"2006-05-05T00:20:47Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Robin Rosenberg (list subscriber)\"  <robin.rosenberg.lists@dewire.com> writes:\n\n> @@ -43,8 +43,13 @@\n>                 die(\"No such ref: %s\", refname);\n>\n>         if (oldval) {\n> -               if (memcmp(currsha1, oldsha1, 20))\n> -                       die(\"Ref %s is at %s but expected %s\", refname, sha1_to_hex(currsha1), sha1_to_hex(oldsha1));\n> +               if (memcmp(currsha1, oldsha1, 20)) {\n> +                       char sha1str1[41];\n> +                       char sha1str2[41];\n> +                       strcpy(sha1str1, sha1_to_hex(currsha1));\n> +                       strcpy(sha1str2, sha1_to_hex(oldsha1));\n> +                       die(\"Ref %s is at %s but expected %s\", refname, sha1str1, sha1str2);\n> +               }\n\nYour patch looks correct, but probably is made unnecessary with\nthe \"you can use up to 4 sha1_to_hex() safely\" patch Linus did.\n\nWe have it in \"master\" and my plan is to cherry-pick it to\n\"maint\" branch and included it in the next stale release 1.3.3,\nalong with core.prefersymlinkrefs patch also only in \"master\",\nif we do not hear somebody scream in the next few days.\n"}]}