Return error when not checking out an entry due to dirtiness.
PATCH 1/1 Return error when not checking out an entry due to dirtiness.
Without -f flag, 'git-checkout-index foo.c' issued an error message when foo.c already existed in the working tree and did not match index. However it did not return an error from the underlying checkout_entry() function and resulted in a successful exit(0).
---
* I've made sure that the existing scripts do not use checkout-index without -f in a way that could be affected by this change. However, third-party scripts may be affected by this. Cogito and StGIT should be OK -- they either run checkout with -f, do not check the error return when it does not use -f, or runs checkout without -f in an empty working tree.
checkout-index.c | 11 ++++++++--- entry.c | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-)
5a166f6a9d1b7ca2de673139fbfc4112b1b2e308
checkout-index.c +8 -3
@@ -63,15 +63,20 @@ static int checkout_file(const char *namstatic int checkout_all (void ) { -int i; +int i, errs; -for (i =0 ; i < active_nr ; i++) { +for (errs = i =0 ; i < active_nr ; i++) {struct cache_entry *ce = active_cache[i];if (ce_stage (ce))continue ;if (checkout_entry (ce, &state) <0 ) -return -1 ; + errs++; } +if (errs) +/* we have already done our error reporting. +* exit with the same code as die(). +*/ +exit (128 );return 0 ; }
entry.c +1 -1
@@ -132,7 +132,7 @@ int checkout_entry(struct cache_entry *cif (!state->force) {if (!state->quiet)fprintf (stderr,"git-checkout-index: %s already exists\n" , path); -return 0 ; +return -1 ; }/*
Quoted 26 lines · Junio C Hamano
Without -f flag, 'git-checkout-index
foo.c' issued an error message whenfoo.calready existed in the working tree and did not match index. However it did not return an error from the underlyingcheckout_entry()function and resulted in a successful exit(0).Signed-off-by Junio C Hamano <[email protected]>---
* I've made sure that the existing scripts do not use checkout-index without -f in a way that could be affected by this change. However, third-party scripts may be affected by this. Cogito and StGIT should be OK -- they either run checkout with -f, do not check the error return when it does not use -f, or runs checkout without -f in an empty working tree.
checkout-index.c | 11 ++++++++--- entry.c | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-)
5a166f6a9d1b7ca2de673139fbfc4112b1b2e308
checkout-index.c static int checkout_file(const char *nam · line 68
Quoted 8 lines
checkout-index.c +2
-2@@ -63,15 +63,20 @@ static int checkout_file(const char *namstatic int checkout_all (void ) { -int i; +int i, errs; -for (i =0 ; i < active_nr ; i++) { +for (errs = i =0 ; i < active_nr ; i++) {
This is ugly. Why not just:
errs = 0;
for (i = 0; i < active_nr ; i++) { (errs is in no way the variable controlled by the for).
Signature · 4 lines
Dr. Horst H. von Brand User #22616 counter.li.org Departamento de Informatica Fono: +56 32 654431 Universidad Tecnica Federico Santa Maria +56 32 654239 Casilla 110-V, Valparaiso, Chile Fax: +56 32 797513