Add script for checking out git repositories
This commit is contained in:
parent
4364c6db88
commit
a7e0a60840
1 changed files with 74 additions and 0 deletions
74
scripts/xx_checkout_repo.sh
Executable file
74
scripts/xx_checkout_repo.sh
Executable file
|
@ -0,0 +1,74 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# This scripts checks out spack from the repo
|
||||
# Input arguments:
|
||||
# - repo: url to repo in git format
|
||||
# - release_tag: tag/branch/commit in repo
|
||||
# - release_dir:
|
||||
# - destination: checkout into directory <release_dir>/<destination>
|
||||
#
|
||||
|
||||
_VERBOSITY=1
|
||||
|
||||
if [[ "$#" -ne 4 ]]; then
|
||||
echo "Syntax: $0 repo release_tag release_dir destination"
|
||||
echo "Checkout tag <release_tag> from repo <repo> into path <release_dir>/<destination>."
|
||||
fi
|
||||
|
||||
arg_repo=$1
|
||||
arg_tag=$2
|
||||
arg_dir=$3
|
||||
arg_destination=$4
|
||||
|
||||
log () {
|
||||
local msg=$1
|
||||
if [[ -n $_VERBOSITY ]]; then
|
||||
echo $msg
|
||||
fi
|
||||
}
|
||||
|
||||
# check repository name for plausibility
|
||||
check_repo () {
|
||||
echo $1
|
||||
}
|
||||
|
||||
# modify tag if necessary
|
||||
canonize_tag () {
|
||||
echo $1
|
||||
}
|
||||
|
||||
# create and prepare destination directory
|
||||
create_dir () {
|
||||
local dir=$1
|
||||
local rc
|
||||
|
||||
if [[ -d $dir ]]; then
|
||||
rc=""
|
||||
else
|
||||
mkdir -p $dir
|
||||
chmod g=u $dir
|
||||
rc=$dir
|
||||
fi
|
||||
echo $rc
|
||||
}
|
||||
|
||||
checkout_git () {
|
||||
local repo=$1
|
||||
local tag=$2
|
||||
local dir=$3
|
||||
|
||||
pushd $dir
|
||||
git clone --depth=1 --single-branch --branch=$tag -c feature.manyFiles=true $repo .
|
||||
popd
|
||||
|
||||
}
|
||||
|
||||
repo=$(check_repo $arg_repo)
|
||||
release_tag=$(canonize_tag $arg_tag)
|
||||
destination_dir=$(create_dir $arg_dir/$arg_destination)
|
||||
if [[ -z $destination_dir ]]; then
|
||||
log "Covardly refusing to overwrite existing directory $arg_dir/$arg_destination."
|
||||
else
|
||||
log "Checking out Spack from $repo at tag $release_tag into directory $destination_dir"
|
||||
checkout_git $repo $release_tag $destination_dir
|
||||
fi
|
Loading…
Reference in a new issue