diff options
author | Jonas Gorski <jonas.gorski@gmail.com> | 2016-06-25 15:58:35 +0200 |
---|---|---|
committer | Jonas Gorski <jonas.gorski@gmail.com> | 2016-07-13 16:55:32 +0200 |
commit | 4eb5aad667bc838b8ebb80c9b970d6bb2f6c013d (patch) | |
tree | d6af73aa941a5a83357f0725de24e10730eab208 /scripts | |
parent | efa1960abb390d696704d029507dff671cc271fd (diff) | |
download | openwrt-4eb5aad667bc838b8ebb80c9b970d6bb2f6c013d.tar.gz openwrt-4eb5aad667bc838b8ebb80c9b970d6bb2f6c013d.tar.bz2 openwrt-4eb5aad667bc838b8ebb80c9b970d6bb2f6c013d.zip |
scripts/getver.sh: try to get branch/upstream automatically
Instead of assuming master is the current branch and origin the right
upstream, try to get both dynamically. If the current branch is not
tracking any upstream, use the origin of the master branch.
Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/getver.sh | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/scripts/getver.sh b/scripts/getver.sh index 5d8788f202..38d526cb53 100755 --- a/scripts/getver.sh +++ b/scripts/getver.sh @@ -23,14 +23,23 @@ try_git() { REV="$(git rev-parse HEAD~$((BASE_REV - GET_REV)))" ;; *) - UPSTREAM_BASE="$(git merge-base $GET_REV origin/master)" - UPSTREAM_REV="$(git rev-list reboot..$UPSTREAM_BASE | wc -l | awk '{print $1}')" + BRANCH="$(git rev-parse --abbrev-ref HEAD)" + ORIGIN="$(git rev-parse --symbolic-full-name ${BRANCH}@{u} 2>/dev/null)" + [ -n "$ORIGIN" ] || ORIGIN="$(git rev-parse --symbolic-full-name master@{u} 2>/dev/null)" REV="$(git rev-list reboot..$GET_REV | wc -l | awk '{print $1}')" - if [ -n "$REV" -a -n "$UPSTREAM_REV" -a "$REV" -gt "$UPSTREAM_REV" ]; then - REV="r${UPSTREAM_REV}+$((REV - UPSTREAM_REV))" + + if [ -n "$ORIGIN" ]; then + UPSTREAM_BASE="$(git merge-base $GET_REV $ORIGIN)" + UPSTREAM_REV="$(git rev-list reboot..$UPSTREAM_BASE | wc -l | awk '{print $1}')" else - REV="${REV:+r$REV}" + UPSTREAM_REV=$REV + fi + + if [ "$REV" -gt "$UPSTREAM_REV" ]; then + REV="${UPSTREAM_REV}+$((REV - UPSTREAM_REV))" fi + + REV="${REV:+r$REV}" ;; esac |