| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | . "$(dirname "$0")/testlib.sh" |
| 4 | |
| 5 | if [ $IS_WINDOWS -eq 1 ]; then |
| 6 | echo "skip $0: Windows lacks POSIX permissions" |
| 7 | exit |
| 8 | fi |
| 9 | |
| 10 | clean_setup () { |
| 11 | mkdir "$1" |
| 12 | cd "$1" |
| 13 | git init |
| 14 | } |
| 15 | |
| 16 | perms_for () { |
| 17 | local file=$(echo "$1" | sed "s!^\(..\)\(..\)!.git/lfs/objects/\1/\2/\1\2!") |
| 18 | local perms=$(ls -l "$file" | awk '{print $1}') |
| 19 | # Trim extended attributes: |
| 20 | echo ${perms:0:10} |
| 21 | } |
| 22 | |
| 23 | assert_dir_perms () { |
| 24 | local perms="$1" |
| 25 | [ 0 -eq "$(find .git/lfs -type d -ls | grep -c -vE "$perms")" ] |
| 26 | } |
| 27 | |
| 28 | begin_test "honors umask" |
| 29 | ( |
| 30 | set -e |
| 31 | clean_setup "simple" |
| 32 | |
| 33 | umask 027 |
| 34 | echo "whatever" | git lfs clean | tee clean.log |
| 35 | [ "$(perms_for cd293be6cea034bd45a0352775a219ef5dc7825ce55d1f7dae9762d80ce64411)" = "-rw-r-----" ] |
| 36 | |
| 37 | umask 007 |
| 38 | echo "random" | git lfs clean | tee clean.log |
| 39 | [ "$(perms_for 87c1b129fbadd7b6e9abc0a9ef7695436d767aece042bec198a97e949fcbe14c)" = "-rw-rw----" ] |
| 40 | ) |
| 41 | end_test |
| 42 | |
| 43 | begin_test "honors umask for directories" |
| 44 | ( |
| 45 | set -e |
| 46 | reponame="simple-directories" |
| 47 | setup_remote_repo_with_file "$reponame" "a.dat" |
| 48 | |
| 49 | umask 027 |
| 50 | clone_repo "$reponame" "$reponame-a" |
| 51 | echo "whatever" | git lfs clean |
| 52 | assert_dir_perms "drwxr-[xs]---" |
| 53 | |
| 54 | umask 007 |
| 55 | clone_repo "$reponame" "$reponame-b" |
| 56 | echo "whatever" | git lfs clean |
| 57 | assert_dir_perms "drwxrw[xs]---" |
| 58 | ) |
| 59 | end_test |
| 60 | |
| 61 | # This is tested more comprehensively in the unit tests. |
| 62 | begin_test "honors core.sharedrepository" |
| 63 | ( |
| 64 | set -e |
| 65 | clean_setup "shared-repo" |
| 66 | |
| 67 | umask 027 |
| 68 | git config core.sharedRepository 0660 |
| 69 | echo "whatever" | git lfs clean | tee clean.log |
| 70 | [ "$(perms_for cd293be6cea034bd45a0352775a219ef5dc7825ce55d1f7dae9762d80ce64411)" = "-rw-rw----" ] |
| 71 | |
| 72 | git config core.sharedRepository everybody |
| 73 | echo "random" | git lfs clean | tee clean.log |
| 74 | [ "$(perms_for 87c1b129fbadd7b6e9abc0a9ef7695436d767aece042bec198a97e949fcbe14c)" = "-rw-rw-r--" ] |
| 75 | |
| 76 | git config core.sharedRepository false |
| 77 | echo "something else" | git lfs clean | tee clean.log |
| 78 | [ "$(perms_for a1621be95040239ee14362c16e20510ddc20f527d772d823b2a1679b33f5cd74)" = "-rw-r-----" ] |
| 79 | |
| 80 | umask 007 |
| 81 | echo "who cares" | git lfs clean | tee clean.log |
| 82 | [ "$(perms_for 261ded5f01a8ca18d9fb1958e8f58c53fa77648cc88a6d67c93d241a91133f3e)" = "-rw-rw----" ] |
| 83 | |
| 84 | ) |
| 85 | end_test |
| 86 | |
| 87 | begin_test "honors core.sharedrepository for directories" |
| 88 | ( |
| 89 | set -e |
| 90 | reponame="shared-repo-directories" |
| 91 | setup_remote_repo_with_file "$reponame" "a.dat" |
| 92 | |
| 93 | umask 027 |
| 94 | git config --global core.sharedRepository 0660 |
| 95 | clone_repo "$reponame" "$reponame-a" |
| 96 | echo "whatever" | git lfs clean |
| 97 | assert_dir_perms "drwxrw[xs]---" |
| 98 | |
| 99 | git config --global core.sharedRepository everybody |
| 100 | clone_repo "$reponame" "$reponame-b" |
| 101 | echo "whatever" | git lfs clean |
| 102 | assert_dir_perms "drwxrw[xs]r-x" |
| 103 | |
| 104 | git config --global core.sharedRepository false |
| 105 | clone_repo "$reponame" "$reponame-c" |
| 106 | echo "whatever" | git lfs clean |
| 107 | assert_dir_perms "drwxr-[xs]---" |
| 108 | |
| 109 | umask 007 |
| 110 | clone_repo "$reponame" "$reponame-d" |
| 111 | echo "whatever" | git lfs clean |
| 112 | assert_dir_perms "drwxrw[xs]---" |
| 113 | |
| 114 | git config --global --unset-all core.sharedRepository |
| 115 | ) |
| 116 | end_test |