@@ -1551,7 +1551,11 @@ static int patch_update_file(struct add_p_state *s,
1551
1551
NULL , 0 , NULL , 0 ))
1552
1552
error (_ ("'git apply' failed" ));
1553
1553
}
1554
- repo_refresh_and_write_index (s -> s .r , REFRESH_QUIET , 0 );
1554
+ if (discard_index (s -> s .r -> index ) < 0 ||
1555
+ repo_read_index_preload (s -> s .r , NULL , 0 ) < 0 )
1556
+ return error (_ ("could not read index" ));
1557
+ repo_refresh_and_write_index (s -> s .r , REFRESH_QUIET , 0 , 1 ,
1558
+ NULL , NULL , NULL );
1555
1559
}
1556
1560
1557
1561
putchar ('\n' );
@@ -1594,7 +1598,10 @@ int run_add_p(struct repository *r, enum add_p_mode mode,
1594
1598
s .mode = & patch_mode_stage ;
1595
1599
s .revision = revision ;
1596
1600
1597
- if (repo_refresh_and_write_index (r , REFRESH_QUIET , 0 ) < 0 ||
1601
+ if (repo_read_index_preload (r , NULL , 0 ) < 0 )
1602
+ return error (_ ("could not read index" ));
1603
+ if (repo_refresh_and_write_index (r , REFRESH_QUIET , 0 , 1 ,
1604
+ NULL , NULL , NULL ) < 0 ||
1598
1605
parse_diff (& s , ps ) < 0 ) {
1599
1606
strbuf_release (& s .plain );
1600
1607
strbuf_release (& s .colored );
0 commit comments