| 1 | #!/usr/bin/env bash |
| 2 | # Including in script/integration and every t/t-*.sh file. |
| 3 | |
| 4 | set -e |
| 5 | |
| 6 | UNAME=$(uname -s) |
| 7 | IS_WINDOWS=0 |
| 8 | IS_MAC=0 |
| 9 | X="" |
| 10 | SHASUM="shasum -a 256" |
| 11 | PATH_SEPARATOR="/" |
| 12 | |
| 13 | if [[ $UNAME == MINGW* || $UNAME == MSYS* || $UNAME == CYGWIN* ]] |
| 14 | then |
| 15 | IS_WINDOWS=1 |
| 16 | X=".exe" |
| 17 | |
| 18 | # Windows might be MSYS2 which does not have the shasum Perl wrapper |
| 19 | # script by default, so use sha256sum directly. MacOS on the other hand |
| 20 | # does not have sha256sum, so still use shasum as the default. |
| 21 | SHASUM="sha256sum" |
| 22 | PATH_SEPARATOR="\\" |
| 23 | elif [[ $UNAME == *Darwin* ]] |
| 24 | then |
| 25 | IS_MAC=1 |
| 26 | fi |
| 27 | |
| 28 | # Convert potentially MinGW bash paths to native Windows paths |
| 29 | # Needed to match generic built paths in test scripts to native paths generated from Go |
| 30 | native_path() { |
| 31 | local arg=$1 |
| 32 | if [ $IS_WINDOWS -eq 1 ]; then |
| 33 | # Use params form to avoid interpreting any '\' characters |
| 34 | printf '%s' "$(cygpath -w $arg)" |
| 35 | else |
| 36 | printf '%s' "$arg" |
| 37 | fi |
| 38 | } |
| 39 | |
| 40 | resolve_symlink() { |
| 41 | local arg=$1 |
| 42 | if [ $IS_WINDOWS -eq 1 ]; then |
| 43 | printf '%s' "$arg" |
| 44 | elif [ $IS_MAC -eq 1 ]; then |
| 45 | # no readlink -f on Mac |
| 46 | local oldwd=$(pwd) |
| 47 | local target=$arg |
| 48 | |
| 49 | cd `dirname $target` |
| 50 | target=`basename $target` |
| 51 | while [ -L "$target" ] |
| 52 | do |
| 53 | target=`readlink $target` |
| 54 | cd `dirname $target` |
| 55 | target=`basename $target` |
| 56 | done |
| 57 | |
| 58 | local resolveddir=`pwd -P` |
| 59 | cd "$oldwd" |
| 60 | printf '%s' "$resolveddir/$target" |
| 61 | |
| 62 | else |
| 63 | readlink -f "$arg" |
| 64 | fi |
| 65 | } |
| 66 | |
| 67 | # The root directory for the git-lfs repository by default. |
| 68 | if [ -z "$ROOTDIR" ]; then |
| 69 | ROOTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)" |
| 70 | fi |
| 71 | |
| 72 | # Where Git LFS outputs the compiled binaries |
| 73 | BINPATH="$ROOTDIR/bin" |
| 74 | |
| 75 | # Put bin path on PATH |
| 76 | PATH="$BINPATH:$PATH" |
| 77 | |
| 78 | # Always provide a test dir outside our git repo if not specified |
| 79 | if [ "$IS_MAC" -eq 1 ]; then |
| 80 | TEMPDIR_PREFIX="git-lfs_TEMP" |
| 81 | else |
| 82 | TEMPDIR_PREFIX="git-lfs_TEMP.XXXXXX" |
| 83 | fi |
| 84 | |
| 85 | if [ -z "$GIT_LFS_TEST_DIR" ]; then |
| 86 | GIT_LFS_TEST_DIR="$(mktemp -d -t "$TEMPDIR_PREFIX")" |
| 87 | GIT_LFS_TEST_DIR="$(resolve_symlink "$GIT_LFS_TEST_DIR")" |
| 88 | # cleanup either after single test or at end of integration (except on fail) |
| 89 | RM_GIT_LFS_TEST_DIR="yes" |
| 90 | fi |
| 91 | |
| 92 | # Make these variables available to all test files run in the same shell, |
| 93 | # particularly when setup() is run first by itself to start a single |
| 94 | # common lfstest-gitserver instance. |
| 95 | export GIT_LFS_TEST_DIR RM_GIT_LFS_TEST_DIR |
| 96 | |
| 97 | # create a temporary work space |
| 98 | TMPDIR=$GIT_LFS_TEST_DIR |
| 99 | |
| 100 | # This is unique to every test file, and cleared after every test run. |
| 101 | TRASHDIR="$TMPDIR/$(basename "$0")-$$" |
| 102 | |
| 103 | # The directory that the test Git server works from. This cleared at the |
| 104 | # beginning of every test run. |
| 105 | REMOTEDIR="$ROOTDIR/t/remote" |
| 106 | |
| 107 | # The directory that stores credentials. Credentials are stored in files with |
| 108 | # the username:password with filenames identifying the host (port numbers are |
| 109 | # ignored). |
| 110 | # |
| 111 | # # stores the credentials for http://127.0.0.1:* |
| 112 | # $CREDSDIR/127.0.0.1 |
| 113 | # |
| 114 | # # stores the credentials for http://git-server.com |
| 115 | # $CREDSDIR/git-server.com |
| 116 | # |
| 117 | CREDSDIR="$REMOTEDIR/creds/" |
| 118 | |
| 119 | # This file contains the URL of the test Git server. See the "Test Suite" |
| 120 | # section in t/README.md |
| 121 | LFS_URL_FILE="$REMOTEDIR/url" |
| 122 | |
| 123 | # This file contains the SSL URL of the test Git server. See the "Test Suite" |
| 124 | # section in t/README.md |
| 125 | LFS_SSL_URL_FILE="$REMOTEDIR/sslurl" |
| 126 | |
| 127 | # This file contains the client cert SSL URL of the test Git server. See the "Test Suite" |
| 128 | # section in t/README.md |
| 129 | LFS_CLIENT_CERT_URL_FILE="$REMOTEDIR/clientcerturl" |
| 130 | |
| 131 | # This file contains the self-signed SSL cert of the TLS endpoint of the test Git server. |
| 132 | LFS_CERT_FILE="$REMOTEDIR/cert" |
| 133 | |
| 134 | # This file contains the client certificate of the client cert endpoint of the test Git server. |
| 135 | LFS_CLIENT_CERT_FILE="$REMOTEDIR/client.crt" |
| 136 | |
| 137 | # This file contains the client key of the client cert endpoint of the test Git server. |
| 138 | LFS_CLIENT_KEY_FILE="$REMOTEDIR/client.key" |
| 139 | |
| 140 | # This file contains the encrypted client key of the client cert endpoint of the test Git server. |
| 141 | LFS_CLIENT_KEY_FILE_ENCRYPTED="$REMOTEDIR/client.enc.key" |
| 142 | |
| 143 | # the fake home dir used for the initial setup |
| 144 | TESTHOME="$REMOTEDIR/home" |
| 145 | |
| 146 | # This directory contains the expected output of the "git lfs completion" |
| 147 | # command for different shells. |
| 148 | COMPLETIONSDIR="$ROOTDIR/t/fixtures/completions" |
| 149 | |
| 150 | GIT_LFS_FORCE_PROGRESS=1 |
| 151 | GIT_CONFIG_NOSYSTEM=1 |
| 152 | GIT_TERMINAL_PROMPT=0 |
| 153 | GIT_SSH=lfs-ssh-echo |
| 154 | GIT_TEMPLATE_DIR="$(native_path "$ROOTDIR/t/fixtures/templates")" |
| 155 | LC_ALL=C |
| 156 | |
| 157 | export CREDSDIR |
| 158 | export GIT_LFS_FORCE_PROGRESS |
| 159 | export GIT_CONFIG_NOSYSTEM |
| 160 | export GIT_SSH |
| 161 | export GIT_TEMPLATE_DIR |
| 162 | export LC_ALL |
| 163 | |
| 164 | # Don't fail if run under git rebase -x. |
| 165 | unset GIT_DIR |
| 166 | unset GIT_WORK_TREE |
| 167 | unset GIT_EXEC_PATH |
| 168 | unset GIT_CHERRY_PICK_HELP |
| 169 | |
| 170 | mkdir -p "$TMPDIR" |
| 171 | mkdir -p "$TRASHDIR" |
| 172 | |
| 173 | if [ $IS_WINDOWS -eq 1 ]; then |
| 174 | # prevent Windows OpenSSH from opening GUI prompts |
| 175 | SSH_ASKPASS="" |
| 176 | fi |
| 177 | |
| 178 | . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/testhelpers.sh" |