Johannes Schindelin <johannes.schindelin@xxxxxx> writes: > The function would otherwise pretend to work fine, but totally ignore > the working directory. s/^T/Unless the caller has already read the index, t/; I am not sure if it should be left as the responsibility of the caller (i.e. check the_index.initialized to bark at a caller that forgets to read from an index) or it is OK to unconditionally read from $GIT_INDEX_FILE in a truly libified function. A caller that wants to read from a custom (temporary) index file can choose to make sure it does read_inddex_from() from its custom file before calling this function, but if it forgets to do so, the penalty is severe than ordinary callers who would have read from the normal index file anyway. Even though the word-lego issue would make this particular API not yet suitable, "who is responsible for reading the index" is an orthogonal issue that we can discuss even on this version, so I thought I'd bring it up. > > Signed-off-by: Johannes Schindelin <johannes.schindelin@xxxxxx> > --- > wt-status.c | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/wt-status.c b/wt-status.c > index 792dda9..33dd76f 100644 > --- a/wt-status.c > +++ b/wt-status.c > @@ -1804,6 +1804,13 @@ int require_clean_work_tree(const char *action, const char *hint, int gently) > struct lock_file *lock_file = xcalloc(1, sizeof(*lock_file)); > int err = 0; > > + if (read_cache() < 0) { > + error(_("Could not read index")); > + if (gently) > + return -1; > + exit(1); > + } > + > hold_locked_index(lock_file, 0); > refresh_cache(REFRESH_QUIET); > update_index_if_able(&the_index, lock_file);