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>
Junio C Hamano committed
Dec 7, 2016 at 11:11 UTC
89d38fb26664038a85eb5a0da8fa4d23228e450d
1 file changed
+4
-3
wt-status.c
+4
-3
@@ -2258,11 +2258,12 @@ int has_uncommitted_changes(int ignore_submodules)
2258
int require_clean_work_tree(const char *action, const char *hint, int ignore_submodules, int gently)
2259
{
2260
struct lock_file *lock_file = xcalloc(1, sizeof(*lock_file));
2261
- int err = 0;
2261
+ int err = 0, fd;
2262
2263
- hold_locked_index(lock_file, 0);
2263
+ fd = hold_locked_index(lock_file, 0);
2264
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);
2267
rollback_lock_file(lock_file);
2268
2269
if (has_unstaged_changes(ignore_submodules)) {