{"thread":{"id":"7526","subject":"[PATCH] Fix renaming branch without config file","startedAt":"2007-04-05T14:20:55Z","lastAt":"2007-04-06T11:33:39Z","messageCount":5,"participants":["Geert Bosch","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"38709","messageId":"20070405144359.4B8832A7C67@potomac.gnat.com","threadId":"7526","inReplyTo":null,"subject":"[PATCH] Fix renaming branch without config file","fromName":"Geert Bosch","fromEmail":"bosch@gnat.com","sentAt":"2007-04-05T14:20:55Z","receivedAt":"2007-04-05T14:20:55Z","isPatch":true,"sender":{"key":"bosch@gnat.com","avatar":null},"body":"Make git_config_rename_section return success if no config file\nexists.  Otherwise, renaming a branch would abort, leaving the\nrepository in an inconsistent state.\n\nSigned-off-by: Geert Bosch <bosch@gnat.com>\n---\n config.c |    5 +++--\n 1 files changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/config.c b/config.c\nindex 6479855..70d1055 100644\n--- a/config.c\n+++ b/config.c\n@@ -916,8 +916,8 @@ int git_config_rename_section(const char *old_name, const char *new_name)\n \t}\n \n \tif (!(config_file = fopen(config_filename, \"rb\"))) {\n-\t\tret = error(\"Could not open config file!\");\n-\t\tgoto out;\n+\t\t/* no config file means nothing to rename, no error */\n+\t\tgoto unlock_and_out;\n \t}\n \n \twhile (fgets(buf, sizeof(buf), config_file)) {\n@@ -951,6 +951,7 @@ int git_config_rename_section(const char *old_name, const char *new_name)\n \t\t}\n \t}\n \tfclose(config_file);\n+ unlock_and_out:\n \tif (close(out_fd) || commit_lock_file(lock) < 0)\n \t\t\tret = error(\"Cannot commit config file!\");\n  out:\n-- \n1.4.5-rc0.GIT\n"},{"id":"38711","messageId":"Pine.LNX.4.63.0704051728400.4045@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"7526","inReplyTo":"20070405144359.4B8832A7C67@potomac.gnat.com","subject":"Re: [PATCH] Fix renaming branch without config file","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-04-05T15:30:05Z","receivedAt":"2007-04-05T15:30:05Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 5 Apr 2007, Geert Bosch wrote:\n\n> Make git_config_rename_section return success if no config file\n> exists.\n\nI don't think this is correct. git_config_rename_section() _should_ return \nan error.\n\n> Otherwise, renaming a branch would abort, leaving the repository in an \n> inconsistent state.\n\nThis should take the hint from --rename-section, and print a warning (or \nnot).\n\nCiao,\nDscho\n"},{"id":"38717","messageId":"B0C79D8E-07A8-4178-B0A6-698EB2BB5A2A@gnat.com","threadId":"7526","inReplyTo":"Pine.LNX.4.63.0704051728400.4045@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] Fix renaming branch without config file","fromName":"Geert Bosch","fromEmail":"bosch@gnat.com","sentAt":"2007-04-05T16:00:58Z","receivedAt":"2007-04-05T16:00:58Z","isPatch":true,"sender":{"key":"bosch@gnat.com","avatar":null},"body":"\nOn Apr 5, 2007, at 11:30, Johannes Schindelin wrote:\n> I don't think this is correct. git_config_rename_section() _should_  \n> return\n> an error.\n>\n>> Otherwise, renaming a branch would abort, leaving the repository  \n>> in an\n>> inconsistent state.\n>\n> This should take the hint from --rename-section, and print a  \n> warning (or\n> not).\n\nLooking at the code, I deduced that git_config_rename_section()\nreturns a positive count of sections renamed, 0 if no matching\nsection exists and negative for another error condition.\n\nThe proposed patch makes the behavior of an absent config file the\nsame as the behavior of an empty one, which seems sane to me.\nThere should be no warning, as it is perfectly fine to have no\nconfig file. Could you elaborate on why you believe my patch\nis not correct?\n\nCurrently, a repository without \"config\" file will be messed up by\ntrying to rename a branch, as the rename will mostly succeed but\nleaves the HEAD dangling, requiring manual file editing to recover.\n\n   -Geert\n"},{"id":"38725","messageId":"Pine.LNX.4.63.0704051951170.4045@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"7526","inReplyTo":"B0C79D8E-07A8-4178-B0A6-698EB2BB5A2A@gnat.com","subject":"Re: [PATCH] Fix renaming branch without config file","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-04-05T17:51:57Z","receivedAt":"2007-04-05T17:51:57Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 5 Apr 2007, Geert Bosch wrote:\n\n> \n> On Apr 5, 2007, at 11:30, Johannes Schindelin wrote:\n> > I don't think this is correct. git_config_rename_section() _should_ return\n> > an error.\n> > \n> > > Otherwise, renaming a branch would abort, leaving the repository in an\n> > > inconsistent state.\n> > \n> > This should take the hint from --rename-section, and print a warning (or\n> > not).\n> \n> Looking at the code, I deduced that git_config_rename_section()\n> returns a positive count of sections renamed, 0 if no matching\n> section exists and negative for another error condition.\n\nAh, yes. You are completely right!\n\n> The proposed patch makes the behavior of an absent config file the same \n> as the behavior of an empty one, which seems sane to me. There should be \n> no warning, as it is perfectly fine to have no config file. Could you \n> elaborate on why you believe my patch is not correct?\n\nI elaborate by taking my objections back. Fair enough?\n\nCiao,\nDscho\n"},{"id":"38786","messageId":"F686C01F-FC5B-4644-812D-749960F8F3BA@gnat.com","threadId":"7526","inReplyTo":"Pine.LNX.4.63.0704051951170.4045@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] Fix renaming branch without config file","fromName":"Geert Bosch","fromEmail":"bosch@gnat.com","sentAt":"2007-04-06T11:33:39Z","receivedAt":"2007-04-06T11:33:39Z","isPatch":true,"sender":{"key":"bosch@gnat.com","avatar":null},"body":"\nOn Apr 5, 2007, at 13:51, Johannes Schindelin wrote:\n> Ah, yes. You are completely right!\n>\n>> The proposed patch makes the behavior of an absent config file the  \n>> same\n>> as the behavior of an empty one, which seems sane to me. There  \n>> should be\n>> no warning, as it is perfectly fine to have no config file. Could you\n>> elaborate on why you believe my patch is not correct?\n>\n> I elaborate by taking my objections back. Fair enough?\n\nSure ;-)\n\nThanks for commenting on my patch.\n\n   -Geert\n"}]}