Skip to content

Commit 89d38fb

Browse files
committed
wt-status: implement opportunisitc index update correctly
The require_clean_work_tree() function calls hold_locked_index() with die_on_error=0 to signal that it is OK if it fails to obtain the lock, but unconditionally calls update_index_if_able(), which will try to write into fd=-1. Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 8d7a455 commit 89d38fb

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

wt-status.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2258,11 +2258,12 @@ int has_uncommitted_changes(int ignore_submodules)
22582258
int require_clean_work_tree(const char *action, const char *hint, int ignore_submodules, int gently)
22592259
{
22602260
struct lock_file *lock_file = xcalloc(1, sizeof(*lock_file));
2261-
int err = 0;
2261+
int err = 0, fd;
22622262

2263-
hold_locked_index(lock_file, 0);
2263+
fd = hold_locked_index(lock_file, 0);
22642264
refresh_cache(REFRESH_QUIET);
2265-
update_index_if_able(&the_index, lock_file);
2265+
if (0 <= fd)
2266+
update_index_if_able(&the_index, lock_file);
22662267
rollback_lock_file(lock_file);
22672268

22682269
if (has_unstaged_changes(ignore_submodules)) {

0 commit comments

Comments
 (0)