| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | . "$(dirname "$0")/testlib.sh" |
| 4 | |
| 5 | ensure_git_version_isnt $VERSION_LOWER "2.5.0" |
| 6 | envInitConfig='git config filter.lfs.process = "git-lfs filter-process" |
| 7 | git config filter.lfs.smudge = "git-lfs smudge -- %f" |
| 8 | git config filter.lfs.clean = "git-lfs clean -- %f"' |
| 9 | |
| 10 | if [ "$IS_WINDOWS" -eq 1 ]; then |
| 11 | export MSYS2_ENV_CONV_EXCL="GIT_LFS_TEST_DIR" |
| 12 | fi |
| 13 | |
| 14 | # The "git lfs env" command should ignore this environment variable |
| 15 | # despite the "GIT_" strings in its name and value. |
| 16 | export TEST_GIT_EXAMPLE="GIT_EXAMPLE" |
| 17 | |
| 18 | setup_expected_concurrent_transfers |
| 19 | |
| 20 | begin_test "git worktree" |
| 21 | ( |
| 22 | set -e |
| 23 | reponame="worktree-main" |
| 24 | mkdir $reponame |
| 25 | cd $reponame |
| 26 | git init |
| 27 | |
| 28 | # can't create a worktree until there's 1 commit at least |
| 29 | echo "a" > tmp.txt |
| 30 | git add tmp.txt |
| 31 | git commit -m "Initial commit" |
| 32 | |
| 33 | expected=$(printf "%s\n%s\n |
| 34 | LocalWorkingDir=$(canonical_path_escaped "$TRASHDIR/$reponame") |
| 35 | LocalGitDir=$(canonical_path_escaped "$TRASHDIR/$reponame/.git") |
| 36 | LocalGitStorageDir=$(canonical_path_escaped "$TRASHDIR/$reponame/.git") |
| 37 | LocalMediaDir=$(canonical_path_escaped "$TRASHDIR/$reponame/.git/lfs/objects") |
| 38 | LocalReferenceDirs= |
| 39 | TempDir=$(canonical_path_escaped "$TRASHDIR/$reponame/.git/lfs/tmp") |
| 40 | ConcurrentTransfers=%d |
| 41 | TusTransfers=false |
| 42 | BasicTransfersOnly=false |
| 43 | SkipDownloadErrors=false |
| 44 | FetchRecentAlways=false |
| 45 | FetchRecentRefsDays=7 |
| 46 | FetchRecentCommitsDays=0 |
| 47 | FetchRecentRefsIncludeRemotes=true |
| 48 | PruneOffsetDays=3 |
| 49 | PruneVerifyRemoteAlways=false |
| 50 | PruneVerifyUnreachableAlways=false |
| 51 | PruneRemoteName=origin |
| 52 | LfsStorageDir=$(canonical_path_escaped "$TRASHDIR/$reponame/.git/lfs") |
| 53 | AccessDownload=none |
| 54 | AccessUpload=none |
| 55 | DownloadTransfers=basic,lfs-standalone-file,ssh |
| 56 | UploadTransfers=basic,lfs-standalone-file,ssh |
| 57 | $(escape_path "$(env | grep "^GIT_")") |
| 58 | %s |
| 59 | " "$(git lfs version)" "$(git version)" "$expectedConcurrentTransfers" "$envInitConfig") |
| 60 | actual=$(git lfs env | grep -v "^GIT_EXEC_PATH=") |
| 61 | contains_same_elements "$expected" "$actual" |
| 62 | |
| 63 | worktreename="worktree-2" |
| 64 | git worktree add "$TRASHDIR/$worktreename" |
| 65 | cd "$TRASHDIR/$worktreename" |
| 66 | |
| 67 | # git dir in worktree is like submodules (except path is worktrees) but this |
| 68 | # is only for index, temp etc |
| 69 | # storage of git objects and lfs objects is in the original .git |
| 70 | expected=$(printf "%s\n%s\n |
| 71 | LocalWorkingDir=$(canonical_path_escaped "$TRASHDIR/$worktreename") |
| 72 | LocalGitDir=$(canonical_path_escaped "$TRASHDIR/$reponame/.git/worktrees/$worktreename") |
| 73 | LocalGitStorageDir=$(canonical_path_escaped "$TRASHDIR/$reponame/.git") |
| 74 | LocalMediaDir=$(canonical_path_escaped "$TRASHDIR/$reponame/.git/lfs/objects") |
| 75 | LocalReferenceDirs= |
| 76 | TempDir=$(canonical_path_escaped "$TRASHDIR/$reponame/.git/lfs/tmp") |
| 77 | ConcurrentTransfers=%d |
| 78 | TusTransfers=false |
| 79 | BasicTransfersOnly=false |
| 80 | SkipDownloadErrors=false |
| 81 | FetchRecentAlways=false |
| 82 | FetchRecentRefsDays=7 |
| 83 | FetchRecentCommitsDays=0 |
| 84 | FetchRecentRefsIncludeRemotes=true |
| 85 | PruneOffsetDays=3 |
| 86 | PruneVerifyRemoteAlways=false |
| 87 | PruneVerifyUnreachableAlways=false |
| 88 | PruneRemoteName=origin |
| 89 | LfsStorageDir=$(canonical_path_escaped "$TRASHDIR/$reponame/.git/lfs") |
| 90 | AccessDownload=none |
| 91 | AccessUpload=none |
| 92 | DownloadTransfers=basic,lfs-standalone-file,ssh |
| 93 | UploadTransfers=basic,lfs-standalone-file,ssh |
| 94 | $(escape_path "$(env | grep "^GIT_")") |
| 95 | %s |
| 96 | " "$(git lfs version)" "$(git version)" "$expectedConcurrentTransfers" "$envInitConfig") |
| 97 | actual=$(git lfs env | grep -v "^GIT_EXEC_PATH=") |
| 98 | contains_same_elements "$expected" "$actual" |
| 99 | ) |
| 100 | end_test |
| 101 | |
| 102 | begin_test "git worktree with hooks" |
| 103 | ( |
| 104 | set -e |
| 105 | reponame="worktree-hooks" |
| 106 | mkdir $reponame |
| 107 | cd $reponame |
| 108 | git init |
| 109 | |
| 110 | # can't create a worktree until there's 1 commit at least |
| 111 | echo "a" > tmp.txt |
| 112 | git add tmp.txt |
| 113 | git commit -m "Initial commit" |
| 114 | |
| 115 | worktreename="worktree-2-hook" |
| 116 | git worktree add "$TRASHDIR/$worktreename" |
| 117 | cd "$TRASHDIR/$worktreename" |
| 118 | |
| 119 | # No hooks so far. |
| 120 | [ ! -e "$TRASHDIR/$reponame/.git/worktrees/$worktreename/hooks" ] |
| 121 | [ ! -e "$TRASHDIR/$reponame/.git/hooks/pre-push" ] |
| 122 | |
| 123 | git lfs install |
| 124 | |
| 125 | # Make sure we installed the hooks in the main repo, not the worktree dir. |
| 126 | [ ! -e "$TRASHDIR/$reponame/.git/worktrees/$worktreename/hooks" ] |
| 127 | [ -x "$TRASHDIR/$reponame/.git/hooks/pre-push" ] |
| 128 | ) |
| 129 | end_test |