From edf9ea7cd7d45a3d9d1c36f374609d643e7cff79 Mon Sep 17 00:00:00 2001 From: Denis Lehmann Date: Mon, 16 Oct 2023 13:10:24 +0200 Subject: [PATCH] check if work directory is repository --- gis | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/gis b/gis index 8f596f6..3164e81 100755 --- a/gis +++ b/gis @@ -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