{"thread":{"id":"2009","subject":"[PATCH] Return error when not checking out an entry due to dirtiness.","startedAt":"2005-10-04T05:11:03Z","lastAt":"2005-10-04T05:11:03Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"9654","messageId":"7vu0fxhno8.fsf@assigned-by-dhcp.cox.net","threadId":"2009","inReplyTo":null,"subject":"[PATCH] Return error when not checking out an entry due to dirtiness.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-10-04T05:11:03Z","receivedAt":"2005-10-04T05:11:03Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Without -f flag, 'git-checkout-index foo.c' issued an error message\nwhen foo.c already existed in the working tree and did not match index.\nHowever it did not return an error from the underlying checkout_entry()\nfunction and resulted in a successful exit(0).\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n\n---\n\n * I've made sure that the existing scripts do not use\n   checkout-index without -f in a way that could be affected by\n   this change.  However, third-party scripts may be affected by\n   this.  Cogito and StGIT should be OK -- they either run\n   checkout with -f, do not check the error return when it does\n   not use -f, or runs checkout without -f in an empty working\n   tree.\n\n checkout-index.c |   11 ++++++++---\n entry.c          |    2 +-\n 2 files changed, 9 insertions(+), 4 deletions(-)\n\n5a166f6a9d1b7ca2de673139fbfc4112b1b2e308\ndiff --git a/checkout-index.c b/checkout-index.c\n--- a/checkout-index.c\n+++ b/checkout-index.c\n@@ -63,15 +63,20 @@ static int checkout_file(const char *nam\n \n static int checkout_all(void)\n {\n-\tint i;\n+\tint i, errs;\n \n-\tfor (i = 0; i < active_nr ; i++) {\n+\tfor (errs = i = 0; i < active_nr ; i++) {\n \t\tstruct cache_entry *ce = active_cache[i];\n \t\tif (ce_stage(ce))\n \t\t\tcontinue;\n \t\tif (checkout_entry(ce, &state) < 0)\n-\t\t\treturn -1;\n+\t\t\terrs++;\n \t}\n+\tif (errs)\n+\t\t/* we have already done our error reporting.\n+\t\t * exit with the same code as die().\n+\t\t */\n+\t\texit(128);\n \treturn 0;\n }\n \ndiff --git a/entry.c b/entry.c\n--- a/entry.c\n+++ b/entry.c\n@@ -132,7 +132,7 @@ int checkout_entry(struct cache_entry *c\n \t\tif (!state->force) {\n \t\t\tif (!state->quiet)\n \t\t\t\tfprintf(stderr, \"git-checkout-index: %s already exists\\n\", path);\n-\t\t\treturn 0;\n+\t\t\treturn -1;\n \t\t}\n \n \t\t/*\n"}]}