{"thread":{"id":"6438","subject":"[PATCH] fix reflog entries for \"git-branch\"","startedAt":"2007-01-19T19:51:29Z","lastAt":"2007-01-19T19:51:29Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"32079","messageId":"7vy7nyg5ha.fsf@assigned-by-dhcp.cox.net","threadId":"6438","inReplyTo":null,"subject":"[PATCH] fix reflog entries for \"git-branch\"","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-01-19T19:51:29Z","receivedAt":"2007-01-19T19:51:29Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Even when -l is not given from the command line, the repository\nmay have the configuration variable core.logallrefupdates set,\nor an old-timer might have done \": >.git/logs/refs/heads/new\"\nbefore running \"git branch new\".  In these cases, the code gave\nan uninitialized msg[] from the stack to be written out as the\nreflog message.\n\nThis also passes a different message when '-f' option is used.\nSaying \"git branch -f branch some-commit\" is a moral equilvalent\nof doing \"git-reset some-commit\" while on the branch.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\ndiff --git a/builtin-branch.c b/builtin-branch.c\nindex c760e18..bbac9dc 100644\n--- a/builtin-branch.c\n+++ b/builtin-branch.c\n@@ -316,6 +316,7 @@ static void create_branch(const char *name, const char *start_name,\n \tstruct commit *commit;\n \tunsigned char sha1[20];\n \tchar ref[PATH_MAX], msg[PATH_MAX + 20];\n+\tint forcing = 0;\n \n \tsnprintf(ref, sizeof ref, \"refs/heads/%s\", name);\n \tif (check_ref_format(ref))\n@@ -326,6 +327,7 @@ static void create_branch(const char *name, const char *start_name,\n \t\t\tdie(\"A branch named '%s' already exists.\", name);\n \t\telse if (!strcmp(head, name))\n \t\t\tdie(\"Cannot force update the current branch.\");\n+\t\tforcing = 1;\n \t}\n \n \tif (start_sha1)\n@@ -342,11 +344,15 @@ static void create_branch(const char *name, const char *start_name,\n \tif (!lock)\n \t\tdie(\"Failed to lock ref for update: %s.\", strerror(errno));\n \n-\tif (reflog) {\n+\tif (reflog)\n \t\tlog_all_ref_updates = 1;\n+\n+\tif (forcing)\n+\t\tsnprintf(msg, sizeof msg, \"branch: Reset from %s\",\n+\t\t\t start_name);\n+\telse\n \t\tsnprintf(msg, sizeof msg, \"branch: Created from %s\",\n \t\t\t start_name);\n-\t}\n \n \tif (write_ref_sha1(lock, sha1, msg) < 0)\n \t\tdie(\"Failed to write ref: %s.\", strerror(errno));\n"}]}