summaryrefslogtreecommitdiff
path: root/branch.c
diff options
context:
space:
mode:
authorLibravatar Glen Choo <chooglen@google.com>2022-03-29 20:01:16 +0000
committerLibravatar Junio C Hamano <gitster@pobox.com>2022-03-30 13:40:00 -0700
commit75388bf5b47678c95f24b58007d2b37d744bf0f7 (patch)
tree50d19e2c31589511150e44385974bea0fd62ee23 /branch.c
parentbranch.c: use 'goto cleanup' in setup_tracking() to fix memory leaks (diff)
downloadtgif-75388bf5b47678c95f24b58007d2b37d744bf0f7.tar.xz
branch: support more tracking modes when recursing
"git branch --recurse-submodules" does not propagate "--track=inherit" or "--no-track" to submodules, which causes submodule branches to use the wrong tracking mode [1]. To fix this, pass the correct options to the "submodule--helper create-branch" child process and test for it. While we are refactoring the same code, replace "--track" with the synonymous, but more consistent-looking "--track=direct" option (introduced at the same time as "--track=inherit", d3115660b4 (branch: add flags and config to inherit tracking, 2021-12-20)). [1] This bug is partially a timing issue: "branch --recurse-submodules" was introduced around the same time as "--track=inherit", and even though I rebased "branch --recurse-submodules" on top of that, I had neglected to support the new tracking mode. Omitting "--no-track" was just a plain old mistake, though. Signed-off-by: Glen Choo <chooglen@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'branch.c')
-rw-r--r--branch.c29
1 files changed, 26 insertions, 3 deletions
diff --git a/branch.c b/branch.c
index 47251669e1..608db0fc91 100644
--- a/branch.c
+++ b/branch.c
@@ -233,6 +233,9 @@ static void setup_tracking(const char *new_ref, const char *orig_ref,
struct string_list tracking_srcs = STRING_LIST_INIT_DUP;
int config_flags = quiet ? 0 : BRANCH_CONFIG_VERBOSE;
+ if (!track)
+ BUG("asked to set up tracking, but tracking is disallowed");
+
memset(&tracking, 0, sizeof(tracking));
tracking.spec.dst = (char *)orig_ref;
tracking.srcs = &tracking_srcs;
@@ -529,8 +532,27 @@ static int submodule_create_branch(struct repository *r,
strvec_push(&child.args, "--quiet");
if (reflog)
strvec_push(&child.args, "--create-reflog");
- if (track == BRANCH_TRACK_ALWAYS || track == BRANCH_TRACK_EXPLICIT)
- strvec_push(&child.args, "--track");
+
+ switch (track) {
+ case BRANCH_TRACK_NEVER:
+ strvec_push(&child.args, "--no-track");
+ break;
+ case BRANCH_TRACK_ALWAYS:
+ case BRANCH_TRACK_EXPLICIT:
+ strvec_push(&child.args, "--track=direct");
+ break;
+ case BRANCH_TRACK_OVERRIDE:
+ BUG("BRANCH_TRACK_OVERRIDE cannot be used when creating a branch.");
+ break;
+ case BRANCH_TRACK_INHERIT:
+ strvec_push(&child.args, "--track=inherit");
+ break;
+ case BRANCH_TRACK_UNSPECIFIED:
+ /* Default for "git checkout". No need to pass --track. */
+ case BRANCH_TRACK_REMOTE:
+ /* Default for "git branch". No need to pass --track. */
+ break;
+ }
strvec_pushl(&child.args, name, start_oid, tracking_name, NULL);
@@ -609,7 +631,8 @@ void create_branches_recursively(struct repository *r, const char *name,
* tedious to determine whether or not tracking was set up in the
* superproject.
*/
- setup_tracking(name, tracking_name, track, quiet);
+ if (track)
+ setup_tracking(name, tracking_name, track, quiet);
for (i = 0; i < submodule_entry_list.entry_nr; i++) {
if (submodule_create_branch(