Teach gc --auto to clear the repository before auto packing it to
prevent failures when removing files on Windows.

Also teach the test 'fetching with auto-gc does not lock up' to complain
when it is no longer triggering an auto packing of the repository.

Fixes https://github.com/git-for-windows/git/issues/500

Signed-off-by: Kim Gybels <kgyb...@infogroep.be>
---

Updated after Duy Nguyen's comments:
- use repo_clear instead of close_all_packs, and add the call in
  gc_before_repack intead of just before executing git repack
- use test_i18ngrep instead of grep in updated test

 builtin/gc.c     | 7 +++++++
 t/t5510-fetch.sh | 4 +++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/builtin/gc.c b/builtin/gc.c
index ccfb1ceaeb..22a6fc4863 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -473,6 +473,13 @@ static int report_last_gc_error(void)
 
 static int gc_before_repack(void)
 {
+       /*
+        * Shut down everything, we should have all the info we need
+        * at this point. Leaving some file descriptors open may
+        * prevent them from being removed on Windows.
+        */
+       repo_clear(the_repository);
+
        if (pack_refs && run_command_v_opt(pack_refs_cmd.argv, RUN_GIT_CMD))
                return error(FAILED_RUN, pack_refs_cmd.argv[0]);
 
diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh
index e402aee6a2..ef599c11cd 100755
--- a/t/t5510-fetch.sh
+++ b/t/t5510-fetch.sh
@@ -828,10 +828,12 @@ test_expect_success 'fetching with auto-gc does not lock 
up' '
        test_commit test2 &&
        (
                cd auto-gc &&
+               git config fetch.unpackLimit 1 &&
                git config gc.autoPackLimit 1 &&
                git config gc.autoDetach false &&
                GIT_ASK_YESNO="$D/askyesno" git fetch >fetch.out 2>&1 &&
-               ! grep "Should I try again" fetch.out
+               test_i18ngrep "Auto packing the repository" fetch.out &&
+               test_i18ngrep ! "Should I try again" fetch.out
        )
 '
 
-- 
2.18.0.windows.1

Reply via email to