build script: add .git fallback

This commit is contained in:
boppyt 2021-08-28 22:37:02 -07:00 committed by Francesco Abbate
parent e93bbc559c
commit ea795aa411
1 changed files with 24 additions and 6 deletions

View File

@ -10,7 +10,16 @@ copy_directory_from_repo () {
fi fi
local dirname="$1" local dirname="$1"
local destdir="$2" local destdir="$2"
git archive "$use_branch" "$dirname" --format=tar | tar xf - -C "$destdir" "${tar_options[@]}" _archive "$use_branch" "$dirname" "$destdir" "${tar_options[@]}"
}
_archive () {
if [[ -d ".git" ]]; then
git archive "$1" "$2" --format=tar | tar xf - -C "$3" "$4"
else
echo ".git not found, falling back to UNIX operation"
cp -r "$2" "$3"
fi
} }
# Check if build directory is ok to be used to build. # Check if build directory is ok to be used to build.
@ -20,10 +29,14 @@ build_dir_is_usable () {
echo "invalid build directory, no path allowed: \"$build\"" echo "invalid build directory, no path allowed: \"$build\""
return 1 return 1
fi fi
git ls-files --error-unmatch "$build" &> /dev/null if [[ -d ".git" ]]; then
if [ $? == 0 ]; then git ls-files --error-unmatch "$build" &> /dev/null
echo "invalid path, \"$build\" is under revision control" if [ $? == 0 ]; then
return 1 echo "invalid path, \"$build\" is under revision control"
return 1
fi
else
echo ".git not found, skipping check for revision control"
fi fi
} }
@ -214,7 +227,12 @@ if [ -z ${arch+set} ]; then
fi fi
if [ -z ${use_branch+set} ]; then if [ -z ${use_branch+set} ]; then
use_branch="$(git rev-parse --abbrev-ref HEAD)" if [[ -d ".git" ]]; then
use_branch="$(git rev-parse --abbrev-ref HEAD)"
else
# it really doesn't matter if git isn't present
use_branch="master"
fi
fi fi
build_dir=".build-$arch" build_dir=".build-$arch"