Hi Bruno,

> > 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.

Thank you for looking into this. However, it looks like $GNULIB_SRCDIR is empty 
for us. So, the change doesn't seem to make a difference. Executing bootstrap 
after a revision bump still fails if the bootstrap script was already run 
before.
I like your idea of fetching if the checkout failed though.

The attached diff seems to be working for our use case. Would it be possible to 
apply something like that in gnulib?

Markus
diff -r 0fbf06e4b460 bootstrap-funclib.sh
--- a/bootstrap-funclib.sh      Sat Apr 27 17:33:00 2024 +0200
+++ b/bootstrap-funclib.sh      Sun Apr 28 11:04:52 2024 +0200
@@ -462,7 +462,17 @@
       || 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
@@ -532,7 +542,17 @@
         # The subdirectory 'gnulib' already exists.
         if test -n "$GNULIB_REVISION"; then
           if test -d "$gnulib_path/.git"; then
-            (cd "$gnulib_path" && git checkout "$GNULIB_REVISION") || exit 1
+            # 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_path" \
+              && { git checkout "$GNULIB_REVISION" 2>/dev/null \
+               || { git fetch origin && git checkout "$GNULIB_REVISION"; }
+              }
+            ) || exit $?
           else
             die "Error: GNULIB_REVISION is specified in bootstrap.conf," \
                 "but '$gnulib_path' contains no git history"

Reply via email to