@@ -343,9 +343,13 @@ static char *prepare_index(int argc, const char **argv, const char *prefix, int
343
343
if (!pathspec || !* pathspec ) {
344
344
fd = hold_locked_index (& index_lock , 1 );
345
345
refresh_cache_or_die (refresh_flags );
346
- if (write_cache (fd , active_cache , active_nr ) ||
347
- commit_locked_index (& index_lock ))
348
- die ("unable to write new_index file" );
346
+ if (active_cache_changed ) {
347
+ if (write_cache (fd , active_cache , active_nr ) ||
348
+ commit_locked_index (& index_lock ))
349
+ die ("unable to write new_index file" );
350
+ } else {
351
+ rollback_lock_file (& index_lock );
352
+ }
349
353
commit_style = COMMIT_AS_IS ;
350
354
return get_index_file ();
351
355
}
@@ -1085,9 +1089,11 @@ int cmd_status(int argc, const char **argv, const char *prefix)
1085
1089
1086
1090
fd = hold_locked_index (& index_lock , 0 );
1087
1091
if (0 <= fd ) {
1088
- if (!write_cache (fd , active_cache , active_nr ))
1092
+ if (active_cache_changed &&
1093
+ !write_cache (fd , active_cache , active_nr ))
1089
1094
commit_locked_index (& index_lock );
1090
- rollback_lock_file (& index_lock );
1095
+ else
1096
+ rollback_lock_file (& index_lock );
1091
1097
}
1092
1098
1093
1099
s .is_initial = get_sha1 (s .reference , sha1 ) ? 1 : 0 ;
0 commit comments