Wrong implementations of tools that modify the index can left
some files as merged and unmerged at the same time. Avoid undesiderable
behaviours by handling this situation.

Signed-off-by: Jaime Soriano Pastor <jsorianopas...@gmail.com>
---
 read-cache.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/read-cache.c b/read-cache.c
index 7f5645e..23e46e1 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -935,6 +935,7 @@ static int add_index_entry_with_check(struct index_state 
*istate, struct cache_e
        int ok_to_replace = option & ADD_CACHE_OK_TO_REPLACE;
        int skip_df_check = option & ADD_CACHE_SKIP_DFCHECK;
        int new_only = option & ADD_CACHE_NEW_ONLY;
+       int replaced = 0;
 
        cache_tree_invalidate_path(istate->cache_tree, ce->name);
        pos = index_name_stage_pos(istate, ce->name, ce_namelen(ce), 
ce_stage(ce));
@@ -943,9 +944,10 @@ static int add_index_entry_with_check(struct index_state 
*istate, struct cache_e
        if (pos >= 0) {
                if (!new_only)
                        replace_index_entry(istate, pos, ce);
-               return 0;
-       }
-       pos = -pos-1;
+               pos++;
+               replaced = 1;
+       } else
+               pos = -pos-1;
 
        /*
         * Inserting a merged entry ("stage 0") into the index
@@ -959,6 +961,8 @@ static int add_index_entry_with_check(struct index_state 
*istate, struct cache_e
                }
        }
 
+       if (replaced)
+               return 0;
        if (!ok_to_add)
                return -1;
        if (!verify_path(ce->name))
-- 
2.0.4.1.g8a38f21.dirty

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to