48 lines
1.4 KiB
Plaintext
48 lines
1.4 KiB
Plaintext
# Set up temp Git identity if none is set
|
|
setup_temp_git_identity() {
|
|
export GIT_AUTHOR_NAME="Test User"
|
|
export GIT_AUTHOR_EMAIL="tests@example.com"
|
|
export GIT_COMMITTER_NAME="Test User"
|
|
export GIT_COMMITTER_EMAIL="tests@example.com"
|
|
}
|
|
|
|
# Get temporary directory where test data will be generated.
|
|
# The function echo's the directory.
|
|
get_tmp_dir() {
|
|
local SCRIPT=$(readlink -f "$0")
|
|
local SCRIPT_PATH=$(dirname "$SCRIPT")
|
|
|
|
echo "$(dirname ${0})/tmp/$(basename "${SCRIPT%.*}")"
|
|
}
|
|
|
|
# Setup bare repository which could be used as a server-side upstream.
|
|
# The function echo's the path to the repository.
|
|
setup_bare_origin_repository() {
|
|
local TMP_DIR=`get_tmp_dir`
|
|
local REPO_DIR="${TMP_DIR}/origin/test-repo.git"
|
|
rm -rf "${REPO_DIR}"
|
|
mkdir -p "${REPO_DIR}"
|
|
git -C "${REPO_DIR}" init --bare --initial-branch=main > /dev/null 2>&1
|
|
echo "${REPO_DIR}"
|
|
}
|
|
|
|
# Install hook to the given bare repository.
|
|
# The bare git repository is provided as $1, hook script is provided as $2,
|
|
# and the hook name is provided as $3.
|
|
install_hook() {
|
|
local GIT_DIR="${1}"
|
|
local HOOK_SCRIPT="${2}"
|
|
local HOOK_NAME="${3}"
|
|
cp "${HOOK_SCRIPT}" "${GIT_DIR}/hooks/${HOOK_NAME}"
|
|
}
|
|
|
|
# Clone repository provided via $1. The path to the working directory is
|
|
# echo'd.
|
|
clone_repository() {
|
|
local TMP_DIR=`get_tmp_dir`
|
|
local WORK_GIT_DIR="${TMP_DIR}/checkout/test-repo"
|
|
rm -rf "${WORK_GIT_DIR}"
|
|
git clone "${1}" "${WORK_GIT_DIR}" > /dev/null 2>&1
|
|
echo "${WORK_GIT_DIR}"
|
|
}
|