File tree Expand file tree Collapse file tree 4 files changed +23
-5
lines changed Expand file tree Collapse file tree 4 files changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -263,8 +263,8 @@ static inline int close_lock_file_gently(struct lock_file *lk)
263
263
* nobody else) to inspect the contents you wrote, while still
264
264
* holding the lock yourself.
265
265
*
266
- * * `reopen_lock_file()` to reopen the lockfile. Make further updates
267
- * to the contents.
266
+ * * `reopen_lock_file()` to reopen the lockfile, truncating the existing
267
+ * contents. Write out the new contents.
268
268
*
269
269
* * `commit_lock_file()` to make the final version permanent.
270
270
*/
Original file line number Diff line number Diff line change @@ -161,6 +161,24 @@ test_expect_success PERL 'commit --interactive gives cache-tree on partial commi
161
161
test_cache_tree
162
162
'
163
163
164
+ test_expect_success PERL ' commit -p with shrinking cache-tree' '
165
+ mkdir -p deep/subdir &&
166
+ echo content >deep/subdir/file &&
167
+ git add deep &&
168
+ git commit -m add &&
169
+ git rm -r deep &&
170
+
171
+ before=$(wc -c <.git/index) &&
172
+ git commit -m delete -p &&
173
+ after=$(wc -c <.git/index) &&
174
+
175
+ # double check that the index shrank
176
+ test $before -gt $after &&
177
+
178
+ # and that our index was not corrupted
179
+ git fsck
180
+ '
181
+
164
182
test_expect_success ' commit in child dir has cache-tree' '
165
183
mkdir dir &&
166
184
>dir/child.t &&
Original file line number Diff line number Diff line change @@ -279,7 +279,7 @@ int reopen_tempfile(struct tempfile *tempfile)
279
279
BUG ("reopen_tempfile called for an inactive object" );
280
280
if (0 <= tempfile -> fd )
281
281
BUG ("reopen_tempfile called for an open object" );
282
- tempfile -> fd = open (tempfile -> filename .buf , O_WRONLY );
282
+ tempfile -> fd = open (tempfile -> filename .buf , O_WRONLY | O_TRUNC );
283
283
return tempfile -> fd ;
284
284
}
285
285
Original file line number Diff line number Diff line change @@ -236,8 +236,8 @@ extern int close_tempfile_gently(struct tempfile *tempfile);
236
236
* it (and nobody else) to inspect or even modify the file's
237
237
* contents.
238
238
*
239
- * * `reopen_tempfile()` to reopen the temporary file. Make further
240
- * updates to the contents.
239
+ * * `reopen_tempfile()` to reopen the temporary file, truncating the existing
240
+ * contents. Write out the new contents.
241
241
*
242
242
* * `rename_tempfile()` to move the file to its permanent location.
243
243
*/
You can’t perform that action at this time.
0 commit comments