Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions builtin/checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,10 @@ static int checkout_paths(const struct checkout_opts *opts,
checkout_index = opts->checkout_index;

if (checkout_index) {
/* Some scenarios may update skipworktree bits, such as
* `restore --staged` after `cherry-pick -n` or `reset --soft`
*/
the_repository->index->updated_skipworktree = 1;
if (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))
die(_("unable to write new index file"));
} else {
Expand Down
4 changes: 3 additions & 1 deletion read-cache-ll.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ struct index_state {
drop_cache_tree : 1,
updated_workdir : 1,
updated_skipworktree : 1,
fsmonitor_has_run_once : 1;
fsmonitor_has_run_once : 1,
added_entries_skip_worktree : 1;
enum sparse_index_mode sparse_index;
struct hashmap name_hash;
struct hashmap dir_hash;
Expand Down Expand Up @@ -284,6 +285,7 @@ int is_index_unborn(struct index_state *);
/* For use with `write_locked_index()`. */
#define COMMIT_LOCK (1 << 0)
#define SKIP_IF_UNCHANGED (1 << 1)
#define UPDATE_SKIP_WORKTREE (1 << 2)

/*
* Write the index while holding an already-taken lock. Close the lock,
Expand Down
11 changes: 11 additions & 0 deletions read-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -2959,6 +2959,17 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,

offset = hashfile_total(f);
}
if ((flags & UPDATE_SKIP_WORKTREE)
&& (ce->ce_flags & (CE_ADDED | CE_UPDATE))
&& (ce->ce_flags & CE_SKIP_WORKTREE)) {
/*
* If caller asked us to, clear skip-worktree bit
* when updating/adding entries.
*/
ce->ce_flags &= ~CE_SKIP_WORKTREE;
istate->updated_skipworktree = 1;
}

if (ce_write_entry(f, ce, previous_name, (struct ondisk_cache_entry *)&ondisk) < 0)
err = -1;

Expand Down
16 changes: 15 additions & 1 deletion sequencer.c
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,7 @@ static int do_recursive_merge(struct repository *r,
int clean, show_output;
int i;
struct lock_file index_lock = LOCK_INIT;
int flags;

if (repo_hold_locked_index(r, &index_lock, LOCK_REPORT_ON_ERROR) < 0)
return -1;
Expand Down Expand Up @@ -787,15 +788,28 @@ static int do_recursive_merge(struct repository *r,
* to be replace with the tree the index matched before we
* started doing any picks.
*/
if (opts->no_commit) {
o.repo->index->added_entries_skip_worktree = 0;
}
merge_switch_to_result(&o, head_tree, &result, 1, show_output);
o.repo->index->added_entries_skip_worktree = 1;

clean = result.clean;
if (clean < 0) {
rollback_lock_file(&index_lock);
return clean;
}

flags = 0;
if (core_virtualfilesystem && opts->no_commit) {
/* When using the virtual file system, staged index changes
* should clear SKIP_WORKTREE
*/
flags |= UPDATE_SKIP_WORKTREE;
}

if (write_locked_index(r->index, &index_lock,
COMMIT_LOCK | SKIP_IF_UNCHANGED))
COMMIT_LOCK | SKIP_IF_UNCHANGED | flags) < 0)
/*
* TRANSLATORS: %s will be "revert", "cherry-pick" or
* "rebase".
Expand Down
13 changes: 13 additions & 0 deletions unpack-trees.c
Original file line number Diff line number Diff line change
Expand Up @@ -1852,6 +1852,19 @@ static void mark_new_skip_worktree(struct pattern_list *pl,
enable_fscache(istate->cache_nr);
clear_ce_flags(istate, select_flag, skip_wt_flag, pl, show_progress);
disable_fscache();

/*
* 3. If added_entries_skip_worktree is cleared and we are checking for
* added entries, clear skip_wt_flag from all added entries.
*/
if ((select_flag & CE_ADDED) && !istate->added_entries_skip_worktree) {
for (i = 0; i < istate->cache_nr; i++) {
struct cache_entry *ce = istate->cache[i];
if ((ce->ce_flags & (CE_ADDED | skip_wt_flag))
== (CE_ADDED | skip_wt_flag))
ce->ce_flags &= ~skip_wt_flag;
}
}
}

static void populate_from_existing_patterns(struct unpack_trees_options *o,
Expand Down
Loading