submodule: fall back to remote's HEAD for missing remote.<name>.branch
authorJohannes Schindelin <redacted>
Wed, 24 Jun 2020 14:46:30 +0000 (14:46 +0000)
committerJunio C Hamano <redacted>
Wed, 24 Jun 2020 16:14:21 +0000 (09:14 -0700)
commitf0a96e8d4c98c2394dc726b57b914f95cbc7a0de
tree2a7301f8e80620a8a552ace52d535d87901dd11d
parent4d04658d8b5c72d2ebbb3aec7b06228e2ae1d327
submodule: fall back to remote's HEAD for missing remote.<name>.branch

When `remote.<name>.branch` is not configured, `git submodule update`
currently falls back to using the branch name `master`. A much better
idea, however, is to use the remote `HEAD`: on all Git servers running
reasonably recent Git versions, the symref `HEAD` points to the main
branch.

Note: t7419 demonstrates that there _might_ be use cases out there that
_expect_ `git submodule update --remote` to update submodules to the
remote `master` branch even if the remote `HEAD` points to another
branch. Arguably, this patch makes the behavior more intuitive, but
there is a slight possibility that this might cause regressions in
obscure setups.

Even so, it should be okay to fix this behavior without anything like a
longer transition period:

- The `git submodule update --remote` command is not really common.

- Current Git's behavior when running this command is outright
  confusing, unless the remote repository's current branch _is_ `master`
  (in which case the proposed behavior matches the old behavior).

- If a user encounters a regression due to the changed behavior, the fix
  is actually trivial: setting `submodule.<name>.branch` to `master`
  will reinstate the old behavior.

Helped-by: Philippe Blain <redacted>
Signed-off-by: Johannes Schindelin <redacted>
Signed-off-by: Junio C Hamano <redacted>
Documentation/git-submodule.txt
Documentation/gitmodules.txt
builtin/submodule--helper.c
t/t7406-submodule-update.sh
t/t7419-submodule-set-branch.sh
git clone https://git.99rst.org/PROJECT