f0a96e8d4c
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 <levraiphilippeblain@gmail.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
97 lines
2.0 KiB
Bash
Executable File
97 lines
2.0 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# Copyright (c) 2019 Denton Liu
|
|
#
|
|
|
|
test_description='Test submodules set-branch subcommand
|
|
|
|
This test verifies that the set-branch subcommand of git-submodule is working
|
|
as expected.
|
|
'
|
|
|
|
TEST_NO_CREATE_REPO=1
|
|
. ./test-lib.sh
|
|
|
|
test_expect_success 'submodule config cache setup' '
|
|
mkdir submodule &&
|
|
(cd submodule &&
|
|
git init &&
|
|
echo a >a &&
|
|
git add . &&
|
|
git commit -ma &&
|
|
git checkout -b topic &&
|
|
echo b >a &&
|
|
git add . &&
|
|
git commit -mb
|
|
) &&
|
|
mkdir super &&
|
|
(cd super &&
|
|
git init &&
|
|
git submodule add ../submodule &&
|
|
git commit -m "add submodule"
|
|
)
|
|
'
|
|
|
|
test_expect_success 'ensure submodule branch is unset' '
|
|
(cd super &&
|
|
! grep branch .gitmodules
|
|
)
|
|
'
|
|
|
|
test_expect_success 'test submodule set-branch --branch' '
|
|
(cd super &&
|
|
git submodule set-branch --branch topic submodule &&
|
|
grep "branch = topic" .gitmodules &&
|
|
git submodule update --remote &&
|
|
cat <<-\EOF >expect &&
|
|
b
|
|
EOF
|
|
git -C submodule show -s --pretty=%s >actual &&
|
|
test_cmp expect actual
|
|
)
|
|
'
|
|
|
|
test_expect_success 'test submodule set-branch --default' '
|
|
test_commit -C submodule c &&
|
|
(cd super &&
|
|
git submodule set-branch --default submodule &&
|
|
! grep branch .gitmodules &&
|
|
git submodule update --remote &&
|
|
cat <<-\EOF >expect &&
|
|
c
|
|
EOF
|
|
git -C submodule show -s --pretty=%s >actual &&
|
|
test_cmp expect actual
|
|
)
|
|
'
|
|
|
|
test_expect_success 'test submodule set-branch -b' '
|
|
test_commit -C submodule b &&
|
|
(cd super &&
|
|
git submodule set-branch -b topic submodule &&
|
|
grep "branch = topic" .gitmodules &&
|
|
git submodule update --remote &&
|
|
cat <<-\EOF >expect &&
|
|
b
|
|
EOF
|
|
git -C submodule show -s --pretty=%s >actual &&
|
|
test_cmp expect actual
|
|
)
|
|
'
|
|
|
|
test_expect_success 'test submodule set-branch -d' '
|
|
test_commit -C submodule d &&
|
|
(cd super &&
|
|
git submodule set-branch -d submodule &&
|
|
! grep branch .gitmodules &&
|
|
git submodule update --remote &&
|
|
cat <<-\EOF >expect &&
|
|
d
|
|
EOF
|
|
git -C submodule show -s --pretty=%s >actual &&
|
|
test_cmp expect actual
|
|
)
|
|
'
|
|
|
|
test_done
|