Skip to content

Commit 5cc9522

Browse files
committed
Merge branch 'gc/branch-recurse-submodules'
"git branch" learned the "--recurse-submodules" option. * gc/branch-recurse-submodules: branch.c: use 'goto cleanup' in setup_tracking() to fix memory leaks branch: add --recurse-submodules option for branch creation builtin/branch: consolidate action-picking logic in cmd_branch() branch: add a dry_run parameter to create_branch() branch: make create_branch() always create a branch branch: move --set-upstream-to behavior to dwim_and_setup_tracking()
2 parents 7455e33 + 679e369 commit 5cc9522

16 files changed

+846
-81
lines changed

Documentation/config/advice.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ advice.*::
116116
submoduleAlternateErrorStrategyDie::
117117
Advice shown when a submodule.alternateErrorStrategy option
118118
configured to "die" causes a fatal error.
119+
submodulesNotUpdated::
120+
Advice shown when a user runs a submodule command that fails
121+
because `git submodule update --init` was not run.
119122
addIgnoredFile::
120123
Advice shown if a user attempts to add an ignored file to
121124
the index.

Documentation/config/submodule.txt

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,33 @@ submodule.active::
5959

6060
submodule.recurse::
6161
A boolean indicating if commands should enable the `--recurse-submodules`
62-
option by default.
63-
Applies to all commands that support this option
64-
(`checkout`, `fetch`, `grep`, `pull`, `push`, `read-tree`, `reset`,
65-
`restore` and `switch`) except `clone` and `ls-files`.
62+
option by default. Defaults to false.
63+
+
64+
When set to true, it can be deactivated via the
65+
`--no-recurse-submodules` option. Note that some Git commands
66+
lacking this option may call some of the above commands affected by
67+
`submodule.recurse`; for instance `git remote update` will call
68+
`git fetch` but does not have a `--no-recurse-submodules` option.
69+
For these commands a workaround is to temporarily change the
70+
configuration value by using `git -c submodule.recurse=0`.
71+
+
72+
The following list shows the commands that accept
73+
`--recurse-submodules` and whether they are supported by this
74+
setting.
75+
76+
* `checkout`, `fetch`, `grep`, `pull`, `push`, `read-tree`,
77+
`reset`, `restore` and `switch` are always supported.
78+
* `clone` and `ls-files` are not supported.
79+
* `branch` is supported only if `submodule.propagateBranches` is
80+
enabled
81+
82+
submodule.propagateBranches::
83+
[EXPERIMENTAL] A boolean that enables branching support when
84+
using `--recurse-submodules` or `submodule.recurse=true`.
85+
Enabling this will allow certain commands to accept
86+
`--recurse-submodules` and certain commands that already accept
87+
`--recurse-submodules` will now consider branches.
6688
Defaults to false.
67-
When set to true, it can be deactivated via the
68-
`--no-recurse-submodules` option. Note that some Git commands
69-
lacking this option may call some of the above commands affected by
70-
`submodule.recurse`; for instance `git remote update` will call
71-
`git fetch` but does not have a `--no-recurse-submodules` option.
72-
For these commands a workaround is to temporarily change the
73-
configuration value by using `git -c submodule.recurse=0`.
7489

7590
submodule.fetchJobs::
7691
Specifies how many submodules are fetched/cloned at the same time.

Documentation/git-branch.txt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ SYNOPSIS
1616
[--points-at <object>] [--format=<format>]
1717
[(-r | --remotes) | (-a | --all)]
1818
[--list] [<pattern>...]
19-
'git branch' [--track[=(direct|inherit)] | --no-track] [-f] <branchname> [<start-point>]
19+
'git branch' [--track[=(direct|inherit)] | --no-track] [-f]
20+
[--recurse-submodules] <branchname> [<start-point>]
2021
'git branch' (--set-upstream-to=<upstream> | -u <upstream>) [<branchname>]
2122
'git branch' --unset-upstream [<branchname>]
2223
'git branch' (-m | -M) [<oldbranch>] <newbranch>
@@ -235,6 +236,22 @@ how the `branch.<name>.remote` and `branch.<name>.merge` options are used.
235236
Do not set up "upstream" configuration, even if the
236237
branch.autoSetupMerge configuration variable is set.
237238

239+
--recurse-submodules::
240+
THIS OPTION IS EXPERIMENTAL! Causes the current command to
241+
recurse into submodules if `submodule.propagateBranches` is
242+
enabled. See `submodule.propagateBranches` in
243+
linkgit:git-config[1]. Currently, only branch creation is
244+
supported.
245+
+
246+
When used in branch creation, a new branch <branchname> will be created
247+
in the superproject and all of the submodules in the superproject's
248+
<start-point>. In submodules, the branch will point to the submodule
249+
commit in the superproject's <start-point> but the branch's tracking
250+
information will be set up based on the submodule's branches and remotes
251+
e.g. `git branch --recurse-submodules topic origin/main` will create the
252+
submodule branch "topic" that points to the submodule commit in the
253+
superproject's "origin/main", but tracks the submodule's "origin/main".
254+
238255
--set-upstream::
239256
As this option had confusing syntax, it is no longer supported.
240257
Please use `--track` or `--set-upstream-to` instead.

advice.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ static struct {
7070
[ADVICE_STATUS_HINTS] = { "statusHints", 1 },
7171
[ADVICE_STATUS_U_OPTION] = { "statusUoption", 1 },
7272
[ADVICE_SUBMODULE_ALTERNATE_ERROR_STRATEGY_DIE] = { "submoduleAlternateErrorStrategyDie", 1 },
73+
[ADVICE_SUBMODULES_NOT_UPDATED] = { "submodulesNotUpdated", 1 },
7374
[ADVICE_UPDATE_SPARSE_PATH] = { "updateSparsePath", 1 },
7475
[ADVICE_WAITING_FOR_EDITOR] = { "waitingForEditor", 1 },
7576
};

advice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ struct string_list;
4444
ADVICE_STATUS_HINTS,
4545
ADVICE_STATUS_U_OPTION,
4646
ADVICE_SUBMODULE_ALTERNATE_ERROR_STRATEGY_DIE,
47+
ADVICE_SUBMODULES_NOT_UPDATED,
4748
ADVICE_UPDATE_SPARSE_PATH,
4849
ADVICE_WAITING_FOR_EDITOR,
4950
ADVICE_SKIPPED_CHERRY_PICKS,

0 commit comments

Comments
 (0)