From: W. Trevor King Date: Fri, 23 Nov 2012 15:47:43 +0000 (-0500) Subject: git-submodule init: Record submodule..branch in repository config. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=6734714e90064b3932126565e3027d7edcf45d51;p=git.git 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 --- diff --git a/Documentation/config.txt b/Documentation/config.txt index 11f320b96..1304499a6 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 + local 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 6eed008f2..c51b6aeb1 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 fc08647bf..3dc82379d 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -236,6 +236,24 @@ test_expect_success 'submodule add --local-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