openwrtv3/scripts/getver.sh
John Crispin 59acb0b8f4 scripts: fix getver git dir check
Git internals are referenced by .git which isn't necessarily a
directory. It may also be a file that references the actual .git
directory using the gitdir directive.

If .git is assumed to be a directory the build will not be able to get
the correct version when openwrt is included as a git submodule because
when used as a submodule .git will actually be a file referencing to a
subdirectory in the parent's git dir.

When the correct version is not detected some image generation tools
will fail because the OpenWrt string will be 'OpenWrtunknown' which is
too long for some header formats.

Signed-off-by: Felix Kaechele <heffer@fedoraproject.org>

SVN-Revision: 44452
2015-02-14 20:48:37 +00:00

34 lines
686 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() {
[ -e .git ] || 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"