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 <benpeart@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ben Peart committed
Sep 22, 2017 at 12:35 UTC
7c545be9a1afb8031ff4df618a1f89d0764191cd
1 file changed
+4
-1
builtin/update-index.c
+4
-1
@@ -915,6 +915,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
915
struct refresh_params refresh_args = {0, &has_errors};
916
int lock_error = 0;
917
int split_index = -1;
918
+ int force_write = 0;
919
struct lock_file *lock_file;
920
struct parse_opt_ctx_t ctx;
921
strbuf_getline_fn getline_fn;
@@ -1006,6 +1007,8 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
1007
N_("test if the filesystem supports untracked cache"), UC_TEST),
1008
OPT_SET_INT(0, "force-untracked-cache", &untracked_cache,
1009
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),
1012
OPT_END()
1013
};
1014
@@ -1147,7 +1150,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
1150
die("BUG: bad untracked_cache value: %d", untracked_cache);
1151
}
1152
1150
- if (active_cache_changed) {
1153
+ if (active_cache_changed || force_write) {
1154
if (newfd < 0) {
1155
if (refresh_args.flags & REFRESH_QUIET)
1156
exit(128);