Commit 969a00e0 authored by Vitaly Lipatov's avatar Vitaly Lipatov

functions/common: improve git root detection

parent e87a3b90
...@@ -276,18 +276,30 @@ get_root_git_dir() ...@@ -276,18 +276,30 @@ get_root_git_dir()
{ {
local DIR= local DIR=
local LOCDIR="$1" local LOCDIR="$1"
local RES
# no path if we have no git
which git >/dev/null 2>/dev/null || return 0
if [ -n "$LOCDIR" ] ; then if [ -n "$LOCDIR" ] ; then
cd "$LOCDIR" || fatal "Only dir arg allowed for get_root_git_dir" cd "$LOCDIR" || fatal "Only dir arg allowed for get_root_git_dir"
fi fi
DIR=$(git rev-parse --git-dir 2>/dev/null)/../ || DIR= DIR=$(git rev-parse --git-dir 2>/dev/null)/../
RES=$?
if [ "$RES" = 0 ] ; then
realpath "$DIR" 2>/dev/null realpath "$DIR" 2>/dev/null
# elif [ "$RES" = 128 ] ; then
# a= git rev-parse --git-dir
# fatal "Check the error above"
fi
if [ -n "$LOCDIR" ] ; then if [ -n "$LOCDIR" ] ; then
cd - >/dev/null cd - >/dev/null
fi fi
return $RES
# FIXME: 1) can return / with good status 2) no one check status later # FIXME: 1) can return / with good status 2) no one check status later
} }
......
...@@ -91,7 +91,7 @@ filter_gear_name() ...@@ -91,7 +91,7 @@ filter_gear_name()
get_gear_name() get_gear_name()
{ {
local gn local gn
local gitdir=$(get_root_git_dir) local gitdir="$(get_root_git_dir)"
[ -n "$gitdir" ] || return [ -n "$gitdir" ] || return
gn=$(basename "$gitdir" | filter_gear_name) gn=$(basename "$gitdir" | filter_gear_name)
echo "$gn" echo "$gn"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment