[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: gitsub.sh hardcodes origin/master
From: |
Bruno Haible |
Subject: |
Re: gitsub.sh hardcodes origin/master |
Date: |
Fri, 16 Aug 2024 22:17:05 +0200 |
Collin Funk wrote:
> > It would be nice to cover both "master" and "main". I think that would
> > cover 99% percent of cases.
It would still be wrong when a package is using one of the "stable" branches
of gnulib.
Marc Nieper-Wißkirchen wrote:
> I am not an expert in git, but here is some information that will hopefully
> make it work even in cases where the branch is called, say, "develop" or
> "stable":
>
> https://stackoverflow.com/questions/28666357/how-to-get-default-git-branch/50056710#50056710
The two main approaches recommended there are both unreliable and therefore
not applicable here. To see that, take a GNU m4 checkout in branch 'branch-1.4'
and see:
$ git remote show origin|grep 'HEAD branch'
HEAD branch: master
$ git symbolic-ref refs/remotes/origin/HEAD
refs/remotes/origin/master
But we would want 'origin/branch-1.4' as the result here.
The prior knowledge summarization engine produces the same two recommendations;
nothing better.
Here's what I'm committing. Let me know if it does not work in your case.
2024-08-16 Bruno Haible <bruno@clisp.org>
gitsub.sh: For a submodule, merge from the right remote branch.
Reported by Marc Nieper-Wißkirchen <marc.nieper+gnu@gmail.com> at
<https://lists.gnu.org/archive/html/bug-gnulib/2024-08/msg00101.html>.
* top/gitsub.sh (func_upgrade): For a submodule, use 'git branch' to
determine the branch to merge from, instead of assuming that it is
always the 'master' branch.
diff --git a/top/gitsub.sh b/top/gitsub.sh
index 93cc2fb919..38b15a4e24 100755
--- a/top/gitsub.sh
+++ b/top/gitsub.sh
@@ -392,7 +392,17 @@ func_upgrade ()
case " $submodule_names " in *" $1 "*)
# It's a submodule.
if test -z "$needs_init"; then
- (cd "$path" && git fetch && git merge origin/master) ||
func_fatal_error "git operation failed"
+ (cd "$path" \
+ && git fetch \
+ && branch=`git branch --show-current` \
+ && { test -n "$branch" || branch=HEAD; } \
+ && sed_escape_dots='s/\([.]\)/\\\1/g' \
+ && branch_escaped=`echo "$branch" | sed -e "${sed_escape_dots}"` \
+ && remote=`git branch -r | sed -n -e "s| origin/${branch_escaped}
-> ||p"` \
+ && { test -n "$remote" || remote="origin/${branch}"; } \
+ && echo "In subdirectory $path: Running \"git merge $remote\"" \
+ && git merge "$remote"
+ ) || func_fatal_error "git operation failed"
fi
;;
esac