Skip to content

Commit 26370f7

Browse files
committed
git-gui: Prefer version file over git-describe.
Some distributions are using Git for part of their package management system, but unpack Git's own source code for delivery from the .tar.gz. This means that when we walk up the directory tree with git-describe to locate a Git repository, the repository we find is for the distribution and *not* for git-gui. Consequently any tag we might find there is bogus and does not apply to us. In this case the version file should always exist and be readable, as the packager is working from the released .tar.gz sources. So we should always favor the version file over anything git-describe guess for us. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
1 parent ed3adde commit 26370f7

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

GIT-VERSION-GEN

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,25 @@ tree_search ()
2020
done
2121
}
2222

23+
# Always use the tarball version file if found, just
24+
# in case we are somehow contained in a larger git
25+
# repository that doesn't actually track our state.
26+
# (At least one package manager is doing this.)
27+
#
2328
# We may be a subproject, so try looking for the merge
2429
# commit that supplied this directory content if we are
2530
# not at the toplevel. We probably will always be the
2631
# second parent in the commit, but we shouldn't rely on
2732
# that fact.
2833
#
2934
# 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.
35+
# try looking for a gitgui-* tag.
3236

33-
if prefix="$(git rev-parse --show-prefix 2>/dev/null)"
37+
if test -f version &&
38+
VN=$(cat version)
39+
then
40+
: happy
41+
elif prefix="$(git rev-parse --show-prefix 2>/dev/null)"
3442
test -n "$prefix" &&
3543
head=$(git rev-list --max-count=1 HEAD -- . 2>/dev/null) &&
3644
tree=$(git rev-parse --verify "HEAD:$prefix" 2>/dev/null) &&
@@ -48,9 +56,6 @@ elif VN=$(git describe --abbrev=4 HEAD 2>/dev/null) &&
4856
esac
4957
then
5058
VN=$(echo "$VN" | sed -e 's/^gitgui-//;s/-/./g');
51-
elif test -f version
52-
then
53-
VN=$(cat version) || VN="$DEF_VER"
5459
else
5560
VN="$DEF_VER"
5661
fi

0 commit comments

Comments
 (0)