submodule add: If --branch is given, record it in .gitmodules

This allows you to easily record a submodule.<name>.branch option in .gitmodules when you add a new submodule. With this patch, $ git submodule add -b <branch> <repository> [<path>] $ git config -f .gitmodules submodule.<path>.branch <branch> reduces to $ git submodule add -b <branch> <repository> [<path>] This means that future calls to $ git submodule update --remote ... will get updates from the same branch that you used to initialize the submodule, which is usually what you want. Signed-off-by: W. Trevor King <wking@tremily.us> Signed-off-by: Junio C Hamano <gitster@pobox.com>

W. Trevor King committed Dec 19, 2012 at 11:03 UTC b928922727d6691a3bdc28160f93f25712c565f6
3 files changed +7
Documentation/git-submodule.txt
+2
@@ -208,6 +208,8 @@ OPTIONS
208 -b::
209 --branch::
210 Branch of repository to add as submodule.
211 + The name of the branch is recorded as `submodule.<path>.branch` in
212 + `.gitmodules` for `update --remote`.
213
214 -f::
215 --force::
git-submodule.sh
+4
@@ -417,6 +417,10 @@ Use -f if you really want to add it." >&2
417
418 git config -f .gitmodules submodule."$sm_name".path "$sm_path" &&
419 git config -f .gitmodules submodule."$sm_name".url "$repo" &&
420 + if test -n "$branch"
421 + then
422 + git config -f .gitmodules submodule."$sm_name".branch "$branch"
423 + fi &&
424 git add --force .gitmodules ||
425 die "$(eval_gettext "Failed to register submodule '\$sm_path'")"
426 }
t/t7400-submodule-basic.sh
+1
@@ -133,6 +133,7 @@ test_expect_success 'submodule add --branch' '
133 (
134 cd addtest &&
135 git submodule add -b initial "$submodurl" submod-branch &&
136 + test "initial" = "$(git config -f .gitmodules submodule.submod-branch.branch)" &&
137 git submodule init
138 ) &&
139