From 7266ec08ff669719b69fe432ae3fbf597d5674f2 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 23 Nov 2012 10:47:43 -0500 Subject: [PATCH] git-submodule init: Record submodule..branch in repository config. This allows users to override the .gitmodules value with a per-repository value. Signed-off-by: W. Trevor King --- Documentation/config.txt | 9 +++++---- git-submodule.sh | 7 +++++++ t/t7400-submodule-basic.sh | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/Documentation/config.txt b/Documentation/config.txt index 11f320b96..a42741150 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -1994,10 +1994,11 @@ status.submodulesummary:: submodule..path:: submodule..url:: submodule..update:: - The path within this project, URL, and the updating strategy - for a submodule. These variables are initially populated - by 'git submodule init'; edit them to override the - URL and other values found in the `.gitmodules` file. See +submodule..branch:: + The path within this project, URL, the updating strategy, and the + upstream branch name for a submodule. These variables are initially + populated by 'git submodule init'; edit them to override the URL and + other values found in the `.gitmodules` file. See linkgit:git-submodule[1] and linkgit:gitmodules[5] for details. submodule..fetchRecurseSubmodules:: diff --git a/git-submodule.sh b/git-submodule.sh index 3a1954035..3c3bb3f0e 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -505,6 +505,13 @@ cmd_init() test -n "$(git config submodule."$name".update)" || git config submodule."$name".update "$upd" || die "$(eval_gettext "Failed to register update mode for submodule path '\$sm_path'")" + + # Copy "branch" setting when it is not set yet + branch="$(git config -f .gitmodules submodule."$name".branch)" + test -z "$branch" || + test -n "$(git config submodule."$name".branch)" || + git config submodule."$name".branch "$branch" || + die "$(eval_gettext "Failed to register branch for submodule path '\$sm_path'")" done } diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index 829d37785..f1160ebc9 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -236,6 +236,24 @@ test_expect_success 'submodule add --follow-branch= --branch' ' ) ' +test_expect_success 'init should register submodule branch in .git/config' ' + ( + cd addtest && + git submodule init && + test "$(git config submodule.submod-follow.branch)" = "final" + ) +' + +test_expect_success 'local config should override .gitmodules branch' ' + ( + cd addtest && + rm -fr submod-follow && + git config submodule.submod-follow.branch initial + git submodule init && + test "$(git config submodule.submod-follow.branch)" = "initial" + ) +' + test_expect_success 'setup - add an example entry to .gitmodules' ' GIT_CONFIG=.gitmodules \ git config submodule.example.url git://example.com/init.git -- 2.26.2