From: Junio C Hamano Date: Mon, 24 Sep 2018 17:30:46 +0000 (-0700) Subject: Merge branch 'jk/reopen-tempfile-truncate' X-Git-Tag: v2.20.0-rc0~220 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/48a81ed29795da3e4cc40d4e5ea535878e4f2d9f?ds=inline;hp=-c Merge branch 'jk/reopen-tempfile-truncate' Fix for a long-standing bug that leaves the index file corrupt when it shrinks during a partial commit. * jk/reopen-tempfile-truncate: reopen_tempfile(): truncate opened file --- 48a81ed29795da3e4cc40d4e5ea535878e4f2d9f diff --combined t/t0090-cache-tree.sh index 7de40141ca,596e269394..94fcb4a78e --- a/t/t0090-cache-tree.sh +++ b/t/t0090-cache-tree.sh @@@ -156,11 -156,29 +156,29 @@@ test_expect_success PERL 'commit --inte return 44; } EOT - (echo p; echo 1; echo; echo s; echo n; echo y; echo q) | + test_write_lines p 1 "" s n y q | git commit --interactive -m foo && test_cache_tree ' + test_expect_success PERL 'commit -p with shrinking cache-tree' ' + mkdir -p deep/subdir && + echo content >deep/subdir/file && + git add deep && + git commit -m add && + git rm -r deep && + + before=$(wc -c <.git/index) && + git commit -m delete -p && + after=$(wc -c <.git/index) && + + # double check that the index shrank + test $before -gt $after && + + # and that our index was not corrupted + git fsck + ' + test_expect_success 'commit in child dir has cache-tree' ' mkdir dir && >dir/child.t && @@@ -239,7 -257,7 +257,7 @@@ test_expect_success 'no phantom error w >newdir/one && git add newdir/one && git checkout 2>errors && - ! test -s errors + test_must_be_empty errors ' test_expect_success 'switching trees does not invalidate shared index' ' diff --combined tempfile.h index 36434eb6fa,b1b085540b..61d8dc4d1b --- a/tempfile.h +++ b/tempfile.h @@@ -2,7 -2,6 +2,7 @@@ #define TEMPFILE_H #include "list.h" +#include "strbuf.h" /* * Handle temporary files. @@@ -236,8 -235,8 +236,8 @@@ extern int close_tempfile_gently(struc * it (and nobody else) to inspect or even modify the file's * contents. * - * * `reopen_tempfile()` to reopen the temporary file. Make further - * updates to the contents. + * * `reopen_tempfile()` to reopen the temporary file, truncating the existing + * contents. Write out the new contents. * * * `rename_tempfile()` to move the file to its permanent location. */