{"thread":{"id":"38705","subject":"[PATCH v2 1/2] git: make \"git -C '' <cmd>\" not to barf","startedAt":"2015-03-05T10:56:07Z","lastAt":"2015-03-05T11:03:56Z","messageCount":2,"participants":["Karthik Nayak"],"isPatch":true,"patchVersion":2,"patchTotal":2},"messages":[{"id":"257067","messageId":"1425552967-22091-1-git-send-email-karthik.188@gmail.com","threadId":"38705","inReplyTo":null,"subject":"[PATCH v2 1/2] git: make \"git -C '' <cmd>\" not to barf","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2015-03-05T10:56:07Z","receivedAt":"2015-03-05T10:56:07Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"It now acts like \"cd ''\" and does not barf and treats\nit as a no-op, this is usefull if a caller function\ndoes not want to change directory and hence gives no\npath value, which would have generally caused git to\noutput an undesired error message.\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n git.c | 12 ++++++++----\n 1 file changed, 8 insertions(+), 4 deletions(-)\n\ndiff --git a/git.c b/git.c\nindex 8c7ee9c..ea92a64 100644\n--- a/git.c\n+++ b/git.c\n@@ -204,10 +204,14 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)\n \t\t\t\tfprintf(stderr, \"No directory given for -C.\\n\" );\n \t\t\t\tusage(git_usage_string);\n \t\t\t}\n-\t\t\tif (chdir((*argv)[1]))\n-\t\t\t\tdie_errno(\"Cannot change to '%s'\", (*argv)[1]);\n-\t\t\tif (envchanged)\n-\t\t\t\t*envchanged = 1;\n+\t\t\tif (*(*argv)[1] == 0)\n+\t\t\t\t; /* Ignore \"\" as a directory */\n+\t\t\telse {\n+\t\t\t\tif (chdir((*argv)[1]))\n+\t\t\t\t\tdie_errno(\"Cannot change to '%s'\", (*argv)[1]);\n+\t\t\t\tif (envchanged)\n+\t\t\t\t\t*envchanged = 1;\n+\t\t\t}\n \t\t\t(*argv)++;\n \t\t\t(*argc)--;\n \t\t} else {\n-- \n2.3.1.167.g7f4ba4b.dirty\n"},{"id":"257070","messageId":"1425553436-23797-1-git-send-email-karthik.188@gmail.com","threadId":"38705","inReplyTo":"1425552967-22091-1-git-send-email-karthik.188@gmail.com","subject":"[PATCH v2 2/2] git-C: Add test to check \"git -C ''\"","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2015-03-05T11:03:56Z","receivedAt":"2015-03-05T11:03:56Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Add a test to check whether \"git -C ''\" works\nwithout giving an error. This is achieved by\nadding a commit and checking the log using\n\"git -C ''\" and comparing the log message with\nthe commit message.\n\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n t/t0056-git-C.sh | 10 ++++++++++\n 1 file changed, 10 insertions(+)\n\ndiff --git a/t/t0056-git-C.sh b/t/t0056-git-C.sh\nindex 99c0377..1cefd4a 100755\n--- a/t/t0056-git-C.sh\n+++ b/t/t0056-git-C.sh\n@@ -1,3 +1,4 @@\n+\n #!/bin/sh\n \n test_description='\"-C <path>\" option and its effects on other path-related options'\n@@ -81,4 +82,13 @@ test_expect_success 'Relative followed by fullpath: \"-C ./here -C /there\" is equ\n \ttest_cmp expected actual\n '\n \n+test_expect_success 'Should not barf when \"git -C \"\" cmd\" is used' '\n+\techo 1 > a.txt &&\n+\tmsg=\"initial a.txt\" &&\n+\t(git add a.txt && git commit -m \"$msg\") &&\n+\techo \"$msg\" >expected &&\n+\tgit -C \"\" log --format=%s >actual &&\n+\ttest_cmp expected actual\n+'\n+\n test_done\n-- \n2.3.1.167.g7f4ba4b.dirty\n"}]}