Make branch merging aware of underlying case-insensitive filsystems
If we find an unexpected file, see if that filename perhaps exists in a case-insensitive way in the index, and whether the file matches that. If so, ignore it as a known pre-existing file of a different name. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Linus Torvalds committed
Mar 22, 2008 at 09:35 UTC
32260ad5dbc3100ebb5e05432198888bfbe600f8
2 files changed
+27
-1
unpack-trees.c
+26
@@ -520,6 +520,22 @@ static int verify_clean_subdirectory(struct cache_entry *ce, const char *action,
520
return cnt;
521
}
522
523
+/*
524
+ * This gets called when there was no index entry for the tree entry 'dst',
525
+ * but we found a file in the working tree that 'lstat()' said was fine,
526
+ * and we're on a case-insensitive filesystem.
527
+ *
528
+ * See if we can find a case-insensitive match in the index that also
529
+ * matches the stat information, and assume it's that other file!
530
+ */
531
+static int icase_exists(struct unpack_trees_options *o, struct cache_entry *dst, struct stat *st)
532
+{
533
+ struct cache_entry *src;
534
+
535
+ src = index_name_exists(o->src_index, dst->name, ce_namelen(dst), 1);
536
+ return src && !ie_match_stat(o->src_index, src, st, CE_MATCH_IGNORE_VALID);
537
+}
538
+
539
/*
540
* We do not want to remove or overwrite a working tree file that
541
* is not tracked, unless it is ignored.
@@ -540,6 +556,16 @@ static int verify_absent(struct cache_entry *ce, const char *action,
556
int dtype = ce_to_dtype(ce);
557
struct cache_entry *result;
558
559
+ /*
560
+ * It may be that the 'lstat()' succeeded even though
561
+ * target 'ce' was absent, because there is an old
562
+ * entry that is different only in case..
563
+ *
564
+ * Ignore that lstat() if it matches.
565
+ */
566
+ if (ignore_case && icase_exists(o, ce, &st))
567
+ return 0;
568
+
569
if (o->dir && excluded(o->dir, ce->name, &dtype))
570
/*
571
* ce->name is explicitly excluded, so it is Ok to
unpack-trees.h
+1
-1
@@ -31,7 +31,7 @@ struct unpack_trees_options {
31
void *unpack_data;
32
33
struct index_state *dst_index;
34
- const struct index_state *src_index;
34
+ struct index_state *src_index;
35
struct index_state result;
36
};
37