b09848cd25
Path to the Git repository directory can be overriden by using the '$GIT_DIR' environment variable. This patch improves detection of Git repository by using 'git-rev-parse', which respects '$GIT_DIR' environment variable, instead of just checking the existence of '.git' directory. Signed-off-by: Vasilis Tsiligiannis <acinonyx@openwrt.gr> SVN-Revision: 49165
35 lines
714 B
Bash
Executable File
35 lines
714 B
Bash
Executable File
#!/usr/bin/env bash
|
|
export LANG=C
|
|
export LC_ALL=C
|
|
[ -n "$TOPDIR" ] && cd $TOPDIR
|
|
|
|
try_version() {
|
|
[ -f version ] || return 1
|
|
REV="$(cat version)"
|
|
[ -n "$REV" ]
|
|
}
|
|
|
|
try_svn() {
|
|
[ -d .svn ] || return 1
|
|
REV="$(svn info | awk '/^Last Changed Rev:/ { print $4 }')"
|
|
REV="${REV:+r$REV}"
|
|
[ -n "$REV" ]
|
|
}
|
|
|
|
try_git() {
|
|
git rev-parse --git-dir >/dev/null 2>&1 || return 1
|
|
REV="$(git log | grep -m 1 git-svn-id | awk '{ gsub(/.*@/, "", $0); print $1 }')"
|
|
REV="${REV:+r$REV}"
|
|
[ -n "$REV" ]
|
|
}
|
|
|
|
try_hg() {
|
|
[ -d .hg ] || return 1
|
|
REV="$(hg log -r-1 --template '{desc}' | awk '{print $2}' | sed 's/\].*//')"
|
|
REV="${REV:+$REV}"
|
|
[ -n "$REV" ]
|
|
}
|
|
|
|
try_version || try_svn || try_git || try_hg || REV="unknown"
|
|
echo "$REV"
|