Skip to content

Commit caea4b8

Browse files
committed
Fix of skip-worktree for cherry-pick --no-commit
1 parent 8e1957d commit caea4b8

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

builtin/checkout.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,10 +641,11 @@ static int checkout_paths(const struct checkout_opts *opts,
641641
checkout_index = opts->checkout_index;
642642

643643
if (checkout_index) {
644-
/* Some scenarios may update skipworktree bits, such as
644+
/* Some scenarios may update skipworktree bits, such as
645645
* `restore --staged` after `cherry-pick -n` or `reset --soft`
646646
*/
647647
the_repository->index->updated_skipworktree = 1;
648+
648649
if (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))
649650
die(_("unable to write new index file"));
650651
} else {

read-cache-ll.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ struct index_state {
176176
drop_cache_tree : 1,
177177
updated_workdir : 1,
178178
updated_skipworktree : 1,
179-
fsmonitor_has_run_once : 1;
179+
fsmonitor_has_run_once : 1,
180+
clear_skip_worktree_for_added_entries : 0;
180181
enum sparse_index_mode sparse_index;
181182
struct hashmap name_hash;
182183
struct hashmap dir_hash;

sequencer.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,7 @@ static int do_recursive_merge(struct repository *r,
753753
int clean, show_output;
754754
int i;
755755
struct lock_file index_lock = LOCK_INIT;
756+
int flags;
756757

757758
if (repo_hold_locked_index(r, &index_lock, LOCK_REPORT_ON_ERROR) < 0)
758759
return -1;
@@ -787,15 +788,34 @@ static int do_recursive_merge(struct repository *r,
787788
* to be replace with the tree the index matched before we
788789
* started doing any picks.
789790
*/
791+
if (opts->no_commit && core_virtualfilesystem) {
792+
/* When using the virtual file system, staged new files
793+
* should clear SKIP_WORKTREE because the virtual file
794+
* system only tracks files that are not modified in index.
795+
* Without this, `restore --staged` will delete the new files
796+
* from disk as well as from index.
797+
*/
798+
o.repo->index->clear_skip_worktree_for_added_entries = 1;
799+
}
790800
merge_switch_to_result(&o, head_tree, &result, 1, show_output);
801+
o.repo->index->clear_skip_worktree_for_added_entries = 0;
802+
791803
clean = result.clean;
792804
if (clean < 0) {
793805
rollback_lock_file(&index_lock);
794806
return clean;
795807
}
796808

809+
flags = 0;
810+
if (core_virtualfilesystem && opts->no_commit) {
811+
/* When using the virtual file system, staged index changes
812+
* should clear SKIP_WORKTREE
813+
*/
814+
flags |= UPDATE_SKIP_WORKTREE;
815+
}
816+
797817
if (write_locked_index(r->index, &index_lock,
798-
COMMIT_LOCK | SKIP_IF_UNCHANGED))
818+
COMMIT_LOCK | SKIP_IF_UNCHANGED | flags) < 0)
799819
/*
800820
* TRANSLATORS: %s will be "revert", "cherry-pick" or
801821
* "rebase".

unpack-trees.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,6 +1852,19 @@ static void mark_new_skip_worktree(struct pattern_list *pl,
18521852
enable_fscache(istate->cache_nr);
18531853
clear_ce_flags(istate, select_flag, skip_wt_flag, pl, show_progress);
18541854
disable_fscache();
1855+
1856+
/*
1857+
* 3. If clear_skip_worktree_for_added_entries is set and we are checking for
1858+
* added entries, clear skip_wt_flag from all added entries.
1859+
*/
1860+
if ((select_flag & CE_ADDED) && istate->clear_skip_worktree_for_added_entries) {
1861+
for (i = 0; i < istate->cache_nr; i++) {
1862+
struct cache_entry *ce = istate->cache[i];
1863+
if ((ce->ce_flags & (CE_ADDED | skip_wt_flag))
1864+
== (CE_ADDED | skip_wt_flag))
1865+
ce->ce_flags &= ~skip_wt_flag;
1866+
}
1867+
}
18551868
}
18561869

18571870
static void populate_from_existing_patterns(struct unpack_trees_options *o,

0 commit comments

Comments
 (0)