@@ -25,6 +25,7 @@
#include "cache-tree.h"
#include "submodule.h"
#include "submodule-config.h"
+#include "dir.h"
#define REFRESH_INDEX_DELAY_WARNING_IN_MS (2 * 1000)
@@ -130,6 +131,7 @@ static void update_index_from_diff(struct diff_queue_struct *q,
int intent_to_add = *(int *)data;
for (i = 0; i < q->nr; i++) {
+ int pos;
struct diff_filespec *one = q->queue[i]->one;
int is_in_reset_tree = one->mode && !is_null_oid(&one->oid);
struct cache_entry *ce;
@@ -141,6 +143,18 @@ static void update_index_from_diff(struct diff_queue_struct *q,
ce = make_cache_entry(&the_index, one->mode, &one->oid, one->path,
0, 0);
+
+ /*
+ * If the file 1) corresponds to an existing index entry with
+ * skip-worktree set, or 2) does not exist in the index but is
+ * outside the sparse checkout definition, add a skip-worktree bit
+ * to the new index entry.
+ */
+ pos = cache_name_pos(one->path, strlen(one->path));
+ if ((pos >= 0 && ce_skip_worktree(active_cache[pos])) ||
+ (pos < 0 && !path_in_sparse_checkout(one->path, &the_index)))
+ ce->ce_flags |= CE_SKIP_WORKTREE;
+
if (!ce)
die(_("make_cache_entry failed for path '%s'"),
one->path);
@@ -459,26 +459,17 @@ test_expect_failure 'blame with pathspec outside sparse definition' '
test_all_match git blame deep/deeper2/deepest/a
'
-# NEEDSWORK: a sparse-checkout behaves differently from a full checkout
-# in this scenario, but it shouldn't.
-test_expect_failure 'checkout and reset (mixed)' '
+test_expect_success 'checkout and reset (mixed)' '
init_repos &&
test_all_match git checkout -b reset-test update-deep &&
test_all_match git reset deepest &&
- test_all_match git reset update-folder1 &&
- test_all_match git reset update-folder2
-'
-
-# NEEDSWORK: a sparse-checkout behaves differently from a full checkout
-# in this scenario, but it shouldn't.
-test_expect_success 'checkout and reset (mixed) [sparse]' '
- init_repos &&
- test_sparse_match git checkout -b reset-test update-deep &&
- test_sparse_match git reset deepest &&
+ # Because skip-worktree is preserved, resetting to update-folder1
+ # will show worktree changes for full-checkout that are not present
+ # in sparse-checkout or sparse-index.
test_sparse_match git reset update-folder1 &&
- test_sparse_match git reset update-folder2
+ run_on_sparse test_path_is_missing folder1
'
test_expect_success 'merge, cherry-pick, and rebase' '
@@ -472,6 +472,23 @@ test_expect_success '--mixed refreshes the index' '
test_cmp expect output
'
+test_expect_success '--mixed preserves skip-worktree' '
+ echo 123 >>file2 &&
+ git add file2 &&
+ git update-index --skip-worktree file2 &&
+ git reset --mixed HEAD >output &&
+ test_must_be_empty output &&
+
+ cat >expect <<-\EOF &&
+ Unstaged changes after reset:
+ M file2
+ EOF
+ git update-index --no-skip-worktree file2 &&
+ git add file2 &&
+ git reset --mixed HEAD >output &&
+ test_cmp expect output
+'
+
test_expect_success 'resetting specific path that is unmerged' '
git rm --cached file2 &&
F1=$(git rev-parse HEAD:file1) &&