Skip to content

Commit 3590a6f

Browse files
dschoGit for Windows Build Agent
authored and
Git for Windows Build Agent
committed
update-index: optionally leave skip-worktree entries alone
While `git update-index` mostly ignores paths referring to index entries whose skip-worktree bit is set, in b4d1690 (Teach Git to respect skip-worktree bit (reading part), 2009-08-20), for reasons that are not entirely obvious, the `--remove` option was made special: it _does_ remove index entries even if their skip-worktree bit is set. Seeing as this behavior has been in place for a decade now, it does not make sense to change it. However, in preparation for fixing a bug in `git stash` where it pretends that skip-worktree entries have actually been removed, we need a mode where `git update-index` leaves all skip-worktree entries alone, even if the `--remove` option was passed. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 543b1be commit 3590a6f

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

Documentation/git-update-index.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ SYNOPSIS
1616
[--chmod=(+|-)x]
1717
[--[no-]assume-unchanged]
1818
[--[no-]skip-worktree]
19+
[--[no-]ignore-skip-worktree-entries]
1920
[--[no-]fsmonitor-valid]
2021
[--ignore-submodules]
2122
[--[no-]split-index]
@@ -113,6 +114,11 @@ you will need to handle the situation manually.
113114
set and unset the "skip-worktree" bit for the paths. See
114115
section "Skip-worktree bit" below for more information.
115116

117+
118+
--[no-]ignore-skip-worktree-entries::
119+
Do not remove skip-worktree (AKA "index-only") entries even when
120+
the `--remove` option was specified.
121+
116122
--[no-]fsmonitor-valid::
117123
When one of these flags is specified, the object name recorded
118124
for the paths are not updated. Instead, these options

builtin/update-index.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ static int verbose;
3535
static int mark_valid_only;
3636
static int mark_skip_worktree_only;
3737
static int mark_fsmonitor_only;
38+
static int ignore_skip_worktree_entries;
3839
#define MARK_FLAG 1
3940
#define UNMARK_FLAG 2
4041
static struct strbuf mtime_dir = STRBUF_INIT;
@@ -381,7 +382,8 @@ static int process_path(const char *path, struct stat *st, int stat_errno)
381382
* so updating it does not make sense.
382383
* On the other hand, removing it from index should work
383384
*/
384-
if (allow_remove && remove_file_from_cache(path))
385+
if (!ignore_skip_worktree_entries && allow_remove &&
386+
remove_file_from_cache(path))
385387
return error("%s: cannot remove from the index", path);
386388
return 0;
387389
}
@@ -1014,6 +1016,8 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
10141016
{OPTION_SET_INT, 0, "no-skip-worktree", &mark_skip_worktree_only, NULL,
10151017
N_("clear skip-worktree bit"),
10161018
PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, UNMARK_FLAG},
1019+
OPT_BOOL(0, "ignore-skip-worktree-entries", &ignore_skip_worktree_entries,
1020+
N_("do not touch index-only entries")),
10171021
OPT_SET_INT(0, "info-only", &info_only,
10181022
N_("add to index only; do not add content to object database"), 1),
10191023
OPT_SET_INT(0, "force-remove", &force_remove,

t/t7012-skip-worktree-writing.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,21 @@ test_expect_success 'git-clean, dirty case' '
134134
test_i18ncmp expected result
135135
'
136136

137+
test_expect_success '--ignore-skip-worktree-entries leaves worktree alone' '
138+
test_commit keep-me &&
139+
git update-index --skip-worktree keep-me.t &&
140+
rm keep-me.t &&
141+
142+
: ignoring the worktree &&
143+
git update-index --remove --ignore-skip-worktree-entries keep-me.t &&
144+
git diff-index --cached --exit-code HEAD &&
145+
146+
: not ignoring the worktree, a deletion is staged &&
147+
git update-index --remove keep-me.t &&
148+
test_must_fail git diff-index --cached --exit-code HEAD \
149+
--diff-filter=D -- keep-me.t
150+
'
151+
137152
#TODO test_expect_failure 'git-apply adds file' false
138153
#TODO test_expect_failure 'git-apply updates file' false
139154
#TODO test_expect_failure 'git-apply removes file' false

0 commit comments

Comments
 (0)