mirror of
https://github.com/Telecominfraproject/OpenNetworkLinux.git
synced 2025-11-04 20:28:17 +00:00
39 lines
765 B
Bash
Executable File
39 lines
765 B
Bash
Executable File
#!/bin/sh
|
|
#
|
|
######################################################################
|
|
#
|
|
# gitroot
|
|
#
|
|
# Translate $1 or $PWD into the top-level workspace directory
|
|
# containing .git
|
|
#
|
|
######################################################################
|
|
|
|
if test $# -gt 0; then
|
|
dir=$(realpath $1)
|
|
else
|
|
dir=$(pwd)
|
|
fi
|
|
while test $dir != /; do
|
|
if test -d $dir/.git; then
|
|
echo $dir
|
|
break
|
|
fi
|
|
if test -f $dir/.git; then
|
|
ndir=$(sed -n -e 's/^gitdir: \(.*\)/\1/p' $dir/.git)
|
|
if test "$ndir"; then
|
|
ndir=$(cd $dir && cd $ndir && pwd)
|
|
ndir=${ndir%/.git/*}
|
|
if test -d "$ndir"; then
|
|
dir=$ndir
|
|
continue
|
|
fi
|
|
fi
|
|
fi
|
|
dir=${dir%/*}
|
|
done
|
|
if test "$dir" = "/"; then
|
|
echo "*** cannot find git root" 1>&2
|
|
exit 1
|
|
fi
|