From: Bryce Glover <randomdsdevel@gmail.com>
To: git@vger.kernel.org
Subject: Automatically Handling Using/Checking Out Branches With One or More Different Contained Submodules?
Date: Tue, 24 Aug 2021 08:00:00 -0400 [thread overview]
Message-ID: <CALH-JHvKjK7KU+Z_R7kG291DQKyb3f=LwxcbP4fn-qL2eeosBQ@mail.gmail.com> (raw)
In-Reply-To: <CALH-JHvNHVvPWap8eiMaQ6HAJOBa4W5xuA9V_s7zPLubgwaRow@mail.gmail.com>
(Note: If this question would fit better on the git-users Google
Group, I apologize, but I saw that, unlike there — unless I overlooked
something? —, you could send messages here even if you weren't a list
subscriber.)
To whom it may concern,
Currently, the only method I've seen that you can reliably use to
switch between different branches when they don't all have the same
contained submodules comes from the Stack Overflow answer at
<https://stackoverflow.com/a/64690495/3319611>. I'll reproduce the
Bash snippet it presents as a solution here for completeness's sake:
```
export TARGET_BRANCH="my-branch-name"
export CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ -f ".gitmodules" ]; then
git submodules deinit --all
mkdir -p .git/git-tools/modules
mv .git/modules .git/git-tools/modules/$CURRENT_BRANCH
fi
git checkout $TARGET_BRANCH
if [ -f ".gitmodules" ]; then
if [ -f ".git/git-tools/modules/$TARGET_BRANCH" ]; then
git mv .git/git-tools/modules/$TARGET_BRANCH .git/modules
fi
git submodule sync && git submodule update --init
fi
```
This involves invoking some actions before '`git checkout`,' so I
couldn't have a couple of Git hooks handle this since, per '`git help
hooks`,' Git doesn't implement a 'pre-checkout' hook, only a
post-checkout one. That wouldn't be enough of a use case to motivate
adding that, though, would it? Alternatively, '`git checkout`'
would, ideally, handle this automatically, perhaps when requested by
flag if it wouldn't make sense for this behavior to be the default
one. I don't know if I'd personally be up to contributing either one
or both of either of those approaches, at least not right away, but,
hypothetically, how involved might that turn out to be?
Curious,
Bryce Glover, an amateur Git user
RandomDSdevel@gmail.com
next parent reply other threads:[~2021-08-24 12:01 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CALH-JHvNHVvPWap8eiMaQ6HAJOBa4W5xuA9V_s7zPLubgwaRow@mail.gmail.com>
2021-08-24 12:00 ` Bryce Glover [this message]
2021-08-27 22:48 ` Automatically Handling Using/Checking Out Branches With One or More Different Contained Submodules? Philippe Blain
2021-08-28 1:23 ` Bryce Glover
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CALH-JHvKjK7KU+Z_R7kG291DQKyb3f=LwxcbP4fn-qL2eeosBQ@mail.gmail.com' \
--to=randomdsdevel@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).