{"thread":{"id":"8468","subject":"[PATCH] git-branch: cleanup config file when deleting branches","startedAt":"2007-06-06T10:09:47Z","lastAt":"2007-06-09T12:35:26Z","messageCount":3,"participants":["Gerrit Pape","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"44153","messageId":"20070606100947.18990.qmail@bef1f6489d171f.315fe32.mid.smarden.org","threadId":"8468","inReplyTo":null,"subject":"[PATCH] git-branch: cleanup config file when deleting branches","fromName":"Gerrit Pape","fromEmail":"pape@smarden.org","sentAt":"2007-06-06T10:09:47Z","receivedAt":"2007-06-06T10:09:47Z","isPatch":true,"sender":{"key":"pape@smarden.org","avatar":"https://avatars.githubusercontent.com/u/143170252?v=4"},"body":"When deleting branches, remove the sections referring to these branches\nfrom the config file.\n\nSigned-off-by: Gerrit Pape <pape@smarden.org>\n---\n builtin-branch.c |    9 +++++++--\n 1 files changed, 7 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin-branch.c b/builtin-branch.c\nindex a5b6bbe..3a70a7d 100644\n--- a/builtin-branch.c\n+++ b/builtin-branch.c\n@@ -85,6 +85,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds)\n \tunsigned char sha1[20];\n \tchar *name = NULL;\n \tconst char *fmt, *remote;\n+\tchar section[PATH_MAX];\n \tint i;\n \tint ret = 0;\n \n@@ -152,9 +153,13 @@ static int delete_branches(int argc, const char **argv, int force, int kinds)\n \t\t\terror(\"Error deleting %sbranch '%s'\", remote,\n \t\t\t       argv[i]);\n \t\t\tret = 1;\n-\t\t} else\n+\t\t} else {\n \t\t\tprintf(\"Deleted %sbranch %s.\\n\", remote, argv[i]);\n-\n+\t\t\tsnprintf(section, sizeof(section), \"branch.%s\",\n+\t\t\t\t argv[i]);\n+\t\t\tif (git_config_rename_section(section, NULL) < 0)\n+\t\t\t\twarning(\"Update of config-file failed\");\n+\t\t}\n \t}\n \n \tif (name)\n-- \n1.5.2\n"},{"id":"44325","messageId":"7vzm3akf6g.fsf@assigned-by-dhcp.cox.net","threadId":"8468","inReplyTo":"20070606100947.18990.qmail@bef1f6489d171f.315fe32.mid.smarden.org","subject":"Re: [PATCH] git-branch: cleanup config file when deleting branches","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-06-08T08:45:27Z","receivedAt":"2007-06-08T08:45:27Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Gerrit Pape <pape@smarden.org> writes:\n\n> When deleting branches, remove the sections referring to these branches\n> from the config file.\n>\n> Signed-off-by: Gerrit Pape <pape@smarden.org>\n\nHmph.  Makes sense and might even be a maint material, but it\nprobably is safe not to do a behaviour change in maint.\n\nTests?\n"},{"id":"44444","messageId":"20070609123526.3856.qmail@5cc189b277f9b4.315fe32.mid.smarden.org","threadId":"8468","inReplyTo":"7vzm3akf6g.fsf@assigned-by-dhcp.cox.net","subject":"[PATCH] git-branch: cleanup config file when deleting branches","fromName":"Gerrit Pape","fromEmail":"pape@smarden.org","sentAt":"2007-06-09T12:35:26Z","receivedAt":"2007-06-09T12:35:26Z","isPatch":true,"sender":{"key":"pape@smarden.org","avatar":"https://avatars.githubusercontent.com/u/143170252?v=4"},"body":"When deleting branches, remove the sections referring to these branches\nfrom the config file.\n\nSigned-off-by: Gerrit Pape <pape@smarden.org>\n---\nOn Fri, Jun 08, 2007 at 01:45:27AM -0700, Junio C Hamano wrote:\n> Hmph.  Makes sense and might even be a maint material, but it\n> probably is safe not to do a behaviour change in maint.\n>\n> Tests?\nSure, two tests added.  Regards, Gerrit.\n\n builtin-branch.c  |    9 +++++++--\n t/t3200-branch.sh |    9 +++++++++\n 2 files changed, 16 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin-branch.c b/builtin-branch.c\nindex 67f46c1..9addd1a 100644\n--- a/builtin-branch.c\n+++ b/builtin-branch.c\n@@ -85,6 +85,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds)\n \tunsigned char sha1[20];\n \tchar *name = NULL;\n \tconst char *fmt, *remote;\n+\tchar section[PATH_MAX];\n \tint i;\n \tint ret = 0;\n \n@@ -152,9 +153,13 @@ static int delete_branches(int argc, const char **argv, int force, int kinds)\n \t\t\terror(\"Error deleting %sbranch '%s'\", remote,\n \t\t\t       argv[i]);\n \t\t\tret = 1;\n-\t\t} else\n+\t\t} else {\n \t\t\tprintf(\"Deleted %sbranch %s.\\n\", remote, argv[i]);\n-\n+\t\t\tsnprintf(section, sizeof(section), \"branch.%s\",\n+\t\t\t\t argv[i]);\n+\t\t\tif (git_config_rename_section(section, NULL) < 0)\n+\t\t\t\twarning(\"Update of config-file failed\");\n+\t\t}\n \t}\n \n \tif (name)\ndiff --git a/t/t3200-branch.sh b/t/t3200-branch.sh\nindex 6f6d884..1322bfb 100755\n--- a/t/t3200-branch.sh\n+++ b/t/t3200-branch.sh\n@@ -171,6 +171,15 @@ test_expect_success 'test tracking setup via --track but deeper' \\\n      test \"$(git-config branch.my7.remote)\" = local &&\n      test \"$(git-config branch.my7.merge)\" = refs/heads/o/o'\n \n+test_expect_success 'test deleting branch deletes branch config' \\\n+    'git-branch -d my7 &&\n+     test \"$(git-config branch.my7.remote)\" = \"\" &&\n+     test \"$(git-config branch.my7.merge)\" = \"\"'\n+\n+test_expect_success 'test deleting branch without config' \\\n+    'git-branch my7 s &&\n+     test \"$(git-branch -d my7)\" = \"Deleted branch my7.\"'\n+\n # Keep this test last, as it changes the current branch\n cat >expect <<EOF\n 0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000\tbranch: Created from master\n-- \n1.5.2.1\n"}]}