Skip to content

Commit 07d082b

Browse files
committed
git-gui: Guess our version accurately as a subproject.
When we are included as a subproject, such as how git.git carries us, we want to retain our own version number and not the version number assigned by git.git's own tags. Consequently we need to locate the correct tag which applies to our tree content and its commit lineage. Signed-off-by: Shawn O. Pearce <[email protected]>
1 parent 6a6459b commit 07d082b

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

GIT-VERSION-GEN

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,45 @@ DEF_VER=0.5.GIT
66
LF='
77
'
88

9-
# First try git-describe, then see if there is a version file
10-
# (included in release tarballs), then default
11-
if VN=$(git describe --abbrev=4 HEAD 2>/dev/null) &&
9+
tree_search ()
10+
{
11+
head=$1
12+
tree=$2
13+
for p in $(git rev-list --parents --max-count=1 $head 2>/devnull)
14+
do
15+
test $tree = $(git rev-parse $p^{tree} 2>/dev/null) &&
16+
vn=$(git describe --abbrev=4 $p 2>/dev/null) &&
17+
case "$vn" in
18+
gitgui-[0-9]*) echo $vn; break;;
19+
esac
20+
done
21+
}
22+
23+
# We may be a subproject, so try looking for the merge
24+
# commit that supplied this directory content if we are
25+
# not at the toplevel. We probably will always be the
26+
# second parent in the commit, but we shouldn't rely on
27+
# that fact.
28+
#
29+
# If we are at the toplevel or the merge assumption fails
30+
# try looking for a gitgui-* tag, or fallback onto the
31+
# distributed version file.
32+
33+
if prefix="$(git rev-parse --show-prefix 2>/dev/null)"
34+
test -n "$prefix" &&
35+
head=$(git rev-list --max-count=1 HEAD -- . 2>/dev/null) &&
36+
tree=$(git rev-parse --verify "HEAD:$prefix" 2>/dev/null) &&
37+
VN=$(tree_search $head $tree)
38+
case "$VN" in
39+
gitgui-[0-9]*) : happy ;;
40+
*) (exit 1) ;;
41+
esac
42+
then
43+
VN=$(echo "$VN" | sed -e 's/^gitgui-//;s/-/./g');
44+
elif VN=$(git describe --abbrev=4 HEAD 2>/dev/null) &&
1245
case "$VN" in
13-
*$LF*) (exit 1) ;;
1446
gitgui-[0-9]*) : happy ;;
47+
*) (exit 1) ;;
1548
esac
1649
then
1750
VN=$(echo "$VN" | sed -e 's/^gitgui-//;s/-/./g');

0 commit comments

Comments
 (0)