setup: fix "inside work tree" detection on case-insensitive filesystems
[gitweb.git] / unpack-trees.c
index 2927660d929eee776d43a87851a928df12b17716..6e9f75549dde32781d6a2b032ab9edb1b7a5e079 100644 (file)
@@ -224,6 +224,9 @@ static int check_updates(struct unpack_trees_options *o)
                struct cache_entry *ce = index->cache[i];
 
                if (ce->ce_flags & CE_UPDATE) {
+                       if (ce->ce_flags & CE_WT_REMOVE)
+                               die("BUG: both update and delete flags are set on %s",
+                                   ce->name);
                        display_progress(progress, ++cnt);
                        ce->ce_flags &= ~CE_UPDATE;
                        if (o->update && !o->dry_run) {
@@ -293,6 +296,7 @@ static int apply_sparse_checkout(struct index_state *istate,
                if (!(ce->ce_flags & CE_UPDATE) && verify_uptodate_sparse(ce, o))
                        return -1;
                ce->ce_flags |= CE_WT_REMOVE;
+               ce->ce_flags &= ~CE_UPDATE;
        }
        if (was_skip_worktree && !ce_skip_worktree(ce)) {
                if (verify_absent_sparse(ce, ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN, o))
@@ -1437,15 +1441,18 @@ static int verify_absent_1(const struct cache_entry *ce,
        if (!len)
                return 0;
        else if (len > 0) {
-               char path[PATH_MAX + 1];
-               memcpy(path, ce->name, len);
-               path[len] = 0;
+               char *path;
+               int ret;
+
+               path = xmemdupz(ce->name, len);
                if (lstat(path, &st))
-                       return error("cannot stat '%s': %s", path,
+                       ret = error("cannot stat '%s': %s", path,
                                        strerror(errno));
-
-               return check_ok_to_remove(path, len, DT_UNKNOWN, NULL, &st,
-                               error_type, o);
+               else
+                       ret = check_ok_to_remove(path, len, DT_UNKNOWN, NULL,
+                                                &st, error_type, o);
+               free(path);
+               return ret;
        } else if (lstat(ce->name, &st)) {
                if (errno != ENOENT)
                        return error("cannot stat '%s': %s", ce->name,