]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'ab/test-cleanly-recreate-trash-directory'
authorJunio C Hamano <gitster@pobox.com>
Mon, 25 Oct 2021 23:07:00 +0000 (16:07 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 25 Oct 2021 23:07:00 +0000 (16:07 -0700)
Improve test framework around unwritable directories.

* ab/test-cleanly-recreate-trash-directory:
  test-lib.sh: try to re-chmod & retry on failed trash removal

1  2 
t/test-lib.sh

diff --cc t/test-lib.sh
index 151da80c56132ba0c705499e88fb611ec1c5ddec,d820910154c3451e9203a59a122125ef50cdd3fc..a291a5d4a2c95a00e189a3f43ac321d4cb732438
        test_done
  fi
  
 +# skip non-whitelisted tests when compiled with SANITIZE=leak
 +if test -n "$SANITIZE_LEAK"
 +then
 +      if test_bool_env GIT_TEST_PASSING_SANITIZE_LEAK false
 +      then
 +              # We need to see it in "git env--helper" (via
 +              # test_bool_env)
 +              export TEST_PASSES_SANITIZE_LEAK
 +
 +              if ! test_bool_env TEST_PASSES_SANITIZE_LEAK false
 +              then
 +                      skip_all="skipping $this_test under GIT_TEST_PASSING_SANITIZE_LEAK=true"
 +                      test_done
 +              fi
 +      fi
 +elif test_bool_env GIT_TEST_PASSING_SANITIZE_LEAK false
 +then
 +      error "GIT_TEST_PASSING_SANITIZE_LEAK=true has no effect except when compiled with SANITIZE=leak"
 +fi
 +
  # Last-minute variable setup
 +USER_HOME="$HOME"
  HOME="$TRASH_DIRECTORY"
  GNUPGHOME="$HOME/gnupg-home-not-used"
 -export HOME GNUPGHOME
 +export HOME GNUPGHOME USER_HOME
  
+ # "rm -rf" existing trash directory, even if a previous run left it
+ # with bad permissions.
+ remove_trash_directory () {
+       dir="$1"
+       if ! rm -rf "$dir" 2>/dev/null
+       then
+               chmod -R u+rwx "$dir"
+               rm -rf "$dir"
+       fi
+       ! test -d "$dir"
+ }
  # Test repository
- rm -fr "$TRASH_DIRECTORY" || {
+ remove_trash_directory "$TRASH_DIRECTORY" || {
        GIT_EXIT_OK=t
        echo >&5 "FATAL: Cannot prepare test area"
        exit 1