Skip to content

Commit b928922

Browse files
wkinggitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 06b1abb commit b928922

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

Documentation/git-submodule.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ OPTIONS
208208
-b::
209209
--branch::
210210
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`.
211213

212214
-f::
213215
--force::

git-submodule.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,10 @@ Use -f if you really want to add it." >&2
417417

418418
git config -f .gitmodules submodule."$sm_name".path "$sm_path" &&
419419
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 &&
420424
git add --force .gitmodules ||
421425
die "$(eval_gettext "Failed to register submodule '\$sm_path'")"
422426
}

t/t7400-submodule-basic.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ test_expect_success 'submodule add --branch' '
133133
(
134134
cd addtest &&
135135
git submodule add -b initial "$submodurl" submod-branch &&
136+
test "initial" = "$(git config -f .gitmodules submodule.submod-branch.branch)" &&
136137
git submodule init
137138
) &&
138139

0 commit comments

Comments
 (0)