Hi Markus, > GNU Octave uses Mercurial as the VCS of its main repository. > Developers are using the bootstrap script of gnulib to automatically clone > its Git repository in a subdirectory of Octave's source tree. The revision > that we'd like to use is set in the bootstrap.conf script. Currently, that is > > : ${GNULIB_REVISION=d4ec02b3cc70cddaaa5183cc5a45814e0afb2292} > > > This is working perfectly for a fresh clone of Octave's source tree. However, > when we update GNULIB_REVISION to a newer revision and a user/developer ran > the bootstrap script before, running the bootstrap script again fails with an > error like the following: > > ./bootstrap: Bootstrapping from checked-out octave sources... > fatal: reference is not a tree: d4ec02b3cc70cddaaa5183cc5a45814e0afb2292 > program finished with exit code 128
I see. Indeed there is no 'git fetch' in the code branch that you are highlighting. > As a workaround we are applying the attached patch to the > bootstrap-funclib.sh script to automatically fetch from the remote gnulib > repository if the GNULIB_REVISION isn't found in the local gnulib Git > repository. Thanks for the patch. But note that GNULIB_REVISION can hold either a commit hash or the name of a branch (such as 'stable-202401'). So, we have 4 cases: (a) a commit hash, already present (b) a commit hash, not known (c) a branch, already present (d) a branch, not known The command 'git cat-file commit $GNULIB_REVISION' returns true in the cases (a) and (c). So, your patch would trigger a 'git fetch' in the cases (b) and (d). But in case (d), the 'git fetch' is useless: 'git cat-file commit $GNULIB_REVISION' would still fail afterwards. One can distinguish the four cases in more detail using the commands git rev-list --quiet $GNULIB_REVISION -- which tests for case (a) and git show-ref --verify --quiet refs/heads/$GNULIB_REVISION which tests for case (c). This would allow us to do 'git fetch' only in case (b). However, I believe the patch below is simpler and achieves the same goal. 2024-04-27 Bruno Haible <br...@clisp.org> bootstrap: Support checking out a recent GNULIB_REVISION. Reported by Markus Mützel <markus.muet...@gmx.de> in <https://lists.gnu.org/archive/html/bug-gnulib/2024-04/msg00462.html>. * top/bootstrap-funclib.sh (prepare_GNULIB_SRCDIR): If the 'git checkout' command fails, fetch the newer commits and then retry it. * build-aux/bootstrap: Regenerated. diff --git a/top/bootstrap-funclib.sh b/top/bootstrap-funclib.sh index 7511d62d9b..620006d320 100644 --- a/top/bootstrap-funclib.sh +++ b/top/bootstrap-funclib.sh @@ -1,6 +1,6 @@ # A library of shell functions for autopull.sh, autogen.sh, and bootstrap. -scriptlibversion=2024-04-13.15; # UTC +scriptlibversion=2024-04-27.17; # UTC # Copyright (C) 2003-2024 Free Software Foundation, Inc. # @@ -462,7 +462,17 @@ prepare_GNULIB_SRCDIR () || die "Error: --gnulib-srcdir or \$GNULIB_SRCDIR is specified," \ "but does not contain gnulib-tool" if test -n "$GNULIB_REVISION" && $use_git; then - (cd "$GNULIB_SRCDIR" && git checkout "$GNULIB_REVISION") || exit $? + # The 'git checkout "$GNULIB_REVISION"' command succeeds if the + # GNULIB_REVISION is a commit hash that exists locally, or if it is + # branch name that can be fetched from origin. It fails, however, + # if the GNULIB_REVISION is a commit hash that only exists in origin. + # In this case, we need a 'git fetch' and then retry + # 'git checkout "$GNULIB_REVISION"'. + (cd "$GNULIB_SRCDIR" \ + && { git checkout "$GNULIB_REVISION" 2>/dev/null \ + || { git fetch origin && git checkout "$GNULIB_REVISION"; } + } + ) || exit $? fi else if ! $use_git; then