Skip to content

Commit 7c545be

Browse files
benpeartgitster
authored andcommitted
update-index: add a new --force-write-index option
At times, it makes sense to avoid the cost of writing out the index when the only changes can easily be recomputed on demand. This causes problems when trying to write test cases to verify that state as they can't guarantee the state has been persisted to disk. Add a new option (--force-write-index) to update-index that will ensure the index is written out even if the cache_changed flag is not set. Signed-off-by: Ben Peart <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3e2c669 commit 7c545be

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

builtin/update-index.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
915915
struct refresh_params refresh_args = {0, &has_errors};
916916
int lock_error = 0;
917917
int split_index = -1;
918+
int force_write = 0;
918919
struct lock_file *lock_file;
919920
struct parse_opt_ctx_t ctx;
920921
strbuf_getline_fn getline_fn;
@@ -1006,6 +1007,8 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
10061007
N_("test if the filesystem supports untracked cache"), UC_TEST),
10071008
OPT_SET_INT(0, "force-untracked-cache", &untracked_cache,
10081009
N_("enable untracked cache without testing the filesystem"), UC_FORCE),
1010+
OPT_SET_INT(0, "force-write-index", &force_write,
1011+
N_("write out the index even if is not flagged as changed"), 1),
10091012
OPT_END()
10101013
};
10111014

@@ -1147,7 +1150,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
11471150
die("BUG: bad untracked_cache value: %d", untracked_cache);
11481151
}
11491152

1150-
if (active_cache_changed) {
1153+
if (active_cache_changed || force_write) {
11511154
if (newfd < 0) {
11521155
if (refresh_args.flags & REFRESH_QUIET)
11531156
exit(128);

0 commit comments

Comments
 (0)