check if work directory is repository

This commit is contained in:
Denis Lehmann 2023-10-16 13:10:24 +02:00
parent 81fa3f69bf
commit edf9ea7cd7

10
gis
View file

@ -75,7 +75,7 @@ while (( "$#" )); do
esac
done
# Add $GIS_PATH or current work directory to paths if none is given
# Add $GIS_PATH, current Git repository or current work directory to paths if none is given
if [ "${paths[*]}" == "" ]; then
if [ "$GIS_PATH" ]; then
OLDIFS=$IFS
@ -90,6 +90,14 @@ fi
git_dirs=()
for path in "${paths[@]}"; do
readarray -t found_git_dirs < <(find "$path" -type d -name ".git" -exec dirname {} \; | sort)
# Check if inside of a repository if none found
if [ "${#found_git_dirs[@]}" -eq 0 ]; then
if git rev-parse > /dev/null 2>&1; then
found_git_dirs+=("$(git rev-parse --show-toplevel)")
fi
fi
git_dirs+=("${found_git_dirs[@]}")
done