]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'ps/t0610-umask-fix'
authorJunio C Hamano <gitster@pobox.com>
Mon, 15 Apr 2024 21:11:43 +0000 (14:11 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 15 Apr 2024 21:11:43 +0000 (14:11 -0700)
The "shared repository" test in the t0610 reftable test failed
under restrictive umask setting (e.g. 007), which has been
corrected.

* ps/t0610-umask-fix:
  t0610: execute git-pack-refs(1) with specified umask
  t0610: make `--shared=` tests reusable

1  2 
t/t0610-reftable-basics.sh

index 931d888bbbcbc426dcf51a0478842fd4787bee1d,5f482377dc6495dc6507aa753f3259d1e871a126..38a535b041961b1921c2d9839b76ac40764316cd
@@@ -96,23 -96,54 +96,54 @@@ test_expect_perms () 
        esac
  }
  
- for umask in 002 022
- do
-       test_expect_success POSIXPERM 'init: honors core.sharedRepository' '
+ test_expect_reftable_perms () {
+       local umask="$1"
+       local shared="$2"
+       local expect="$3"
+       test_expect_success POSIXPERM "init: honors --shared=$shared with umask $umask" '
                test_when_finished "rm -rf repo" &&
                (
                        umask $umask &&
-                       git init --shared=true repo &&
-                       test 1 = "$(git -C repo config core.sharedrepository)"
+                       git init --shared=$shared repo
                ) &&
-               test_expect_perms "-rw-rw-r--" repo/.git/reftable/tables.list &&
+               test_expect_perms "$expect" repo/.git/reftable/tables.list &&
                for table in repo/.git/reftable/*.ref
                do
-                       test_expect_perms "-rw-rw-r--" "$table" ||
+                       test_expect_perms "$expect" "$table" ||
                        return 1
                done
        '
- done
+       test_expect_success POSIXPERM "pack-refs: honors --shared=$shared with umask $umask" '
+               test_when_finished "rm -rf repo" &&
+               (
+                       umask $umask &&
+                       git init --shared=$shared repo &&
+                       test_commit -C repo A &&
+                       test_line_count = 3 repo/.git/reftable/tables.list &&
+                       git -C repo pack-refs
+               ) &&
+               test_expect_perms "$expect" repo/.git/reftable/tables.list &&
+               for table in repo/.git/reftable/*.ref
+               do
+                       test_expect_perms "$expect" "$table" ||
+                       return 1
+               done
+       '
+ }
+ test_expect_reftable_perms 002 umask "-rw-rw-r--"
+ test_expect_reftable_perms 022 umask "-rw-r--r--"
+ test_expect_reftable_perms 027 umask "-rw-r-----"
+ test_expect_reftable_perms 002 group "-rw-rw-r--"
+ test_expect_reftable_perms 022 group "-rw-rw-r--"
+ test_expect_reftable_perms 027 group "-rw-rw----"
+ test_expect_reftable_perms 002 world "-rw-rw-r--"
+ test_expect_reftable_perms 022 world "-rw-rw-r--"
+ test_expect_reftable_perms 027 world "-rw-rw-r--"
  
  test_expect_success 'clone: can clone reftable repository' '
        test_when_finished "rm -rf repo clone" &&
@@@ -328,38 -359,6 +359,38 @@@ test_expect_success 'ref transaction: w
        EOF
  '
  
 +test_expect_success 'ref transaction: empty transaction in empty repo' '
 +      test_when_finished "rm -rf repo" &&
 +      git init repo &&
 +      test_commit -C repo --no-tag A &&
 +      git -C repo update-ref -d refs/heads/main &&
 +      test-tool -C repo ref-store main delete-refs REF_NO_DEREF msg HEAD &&
 +      git -C repo update-ref --stdin <<-EOF
 +      prepare
 +      commit
 +      EOF
 +'
 +
 +test_expect_success 'ref transaction: fails gracefully when auto compaction fails' '
 +      test_when_finished "rm -rf repo" &&
 +      git init repo &&
 +      (
 +              cd repo &&
 +
 +              test_commit A &&
 +              for i in $(test_seq 10)
 +              do
 +                      git branch branch-$i &&
 +                      for table in .git/reftable/*.ref
 +                      do
 +                              touch "$table.lock" || exit 1
 +                      done ||
 +                      exit 1
 +              done &&
 +              test_line_count = 13 .git/reftable/tables.list
 +      )
 +'
 +
  test_expect_success 'pack-refs: compacts tables' '
        test_when_finished "rm -rf repo" &&
        git init repo &&
        test_line_count = 1 repo/.git/reftable/tables.list
  '
  
 +test_expect_success 'pack-refs: compaction raises locking errors' '
 +      test_when_finished "rm -rf repo" &&
 +      git init repo &&
 +      test_commit -C repo A &&
 +      touch repo/.git/reftable/tables.list.lock &&
 +      cat >expect <<-EOF &&
 +      error: unable to compact stack: data is locked
 +      EOF
 +      test_must_fail git -C repo pack-refs 2>err &&
 +      test_cmp expect err
 +'
 +
 +for command in pack-refs gc "maintenance run --task=pack-refs"
 +do
 +test_expect_success "$command: auto compaction" '
 +      test_when_finished "rm -rf repo" &&
 +      git init repo &&
 +      (
 +              cd repo &&
 +
 +              test_commit A &&
 +
 +              # We need a bit of setup to ensure that git-gc(1) actually
 +              # triggers, and that it does not write anything to the refdb.
 +              git config gc.auto 1 &&
 +              git config gc.autoDetach 0 &&
 +              git config gc.reflogExpire never &&
 +              git config gc.reflogExpireUnreachable never &&
 +              test_oid blob17_1 | git hash-object -w --stdin &&
 +
 +              # The tables should have been auto-compacted, and thus auto
 +              # compaction should not have to do anything.
 +              ls -1 .git/reftable >tables-expect &&
 +              test_line_count = 4 tables-expect &&
 +              git $command --auto &&
 +              ls -1 .git/reftable >tables-actual &&
 +              test_cmp tables-expect tables-actual &&
 +
 +              test_oid blob17_2 | git hash-object -w --stdin &&
 +
 +              # Lock all tables write some refs. Auto-compaction will be
 +              # unable to compact tables and thus fails gracefully, leaving
 +              # the stack in a sub-optimal state.
 +              ls .git/reftable/*.ref |
 +              while read table
 +              do
 +                      touch "$table.lock" || exit 1
 +              done &&
 +              git branch B &&
 +              git branch C &&
 +              rm .git/reftable/*.lock &&
 +              test_line_count = 5 .git/reftable/tables.list &&
 +
 +              git $command --auto &&
 +              test_line_count = 1 .git/reftable/tables.list
 +      )
 +'
 +done
 +
  test_expect_success 'pack-refs: prunes stale tables' '
        test_when_finished "rm -rf repo" &&
        git init repo &&
@@@ -450,26 -390,6 +481,6 @@@ test_expect_success 'pack-refs: does no
        test_path_is_file repo/.git/reftable/garbage
  '
  
- for umask in 002 022
- do
-       test_expect_success POSIXPERM 'pack-refs: honors core.sharedRepository' '
-               test_when_finished "rm -rf repo" &&
-               (
-                       umask $umask &&
-                       git init --shared=true repo &&
-                       test_commit -C repo A &&
-                       test_line_count = 3 repo/.git/reftable/tables.list
-               ) &&
-               git -C repo pack-refs &&
-               test_expect_perms "-rw-rw-r--" repo/.git/reftable/tables.list &&
-               for table in repo/.git/reftable/*.ref
-               do
-                       test_expect_perms "-rw-rw-r--" "$table" ||
-                       return 1
-               done
-       '
- done
  test_expect_success 'packed-refs: writes are synced' '
        test_when_finished "rm -rf repo" &&
        git init repo &&