From: "W. Trevor King" <wk...@tremily.us>

This allows users to override the .gitmodules value with a
per-repository value.

Signed-off-by: W. Trevor King <wk...@tremily.us>
---
 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 11f320b..1304499 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1994,10 +1994,11 @@ status.submodulesummary::
 submodule.<name>.path::
 submodule.<name>.url::
 submodule.<name>.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.<name>.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.<name>.fetchRecurseSubmodules::
diff --git a/git-submodule.sh b/git-submodule.sh
index 6eed008..c51b6ae 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 fc08647..3dc8237 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -236,6 +236,24 @@ test_expect_success 'submodule add --local-branch=<name> 
--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
-- 
1.8.0.3.g95edff1.dirty

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to