summaryrefslogtreecommitdiff
path: root/branch.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2022-05-26 21:51:30 (GMT)
committerJunio C Hamano <gitster@pobox.com>2022-05-26 21:51:30 (GMT)
commitf49c478f628910de206c5e882a3cd3abec76d4e6 (patch)
treede71e2834c8cd48e6c2aaf447453d408d67fced0 /branch.c
parent6afdb07b7b918ed9282ea6e955f53369df862be8 (diff)
parent05d57750c66e4b58233787954c06b8f714bbee75 (diff)
downloadgit-f49c478f628910de206c5e882a3cd3abec76d4e6.zip
git-f49c478f628910de206c5e882a3cd3abec76d4e6.tar.gz
git-f49c478f628910de206c5e882a3cd3abec76d4e6.tar.bz2
Merge branch 'tk/simple-autosetupmerge'
"git -c branch.autosetupmerge=simple branch $A $B" will set the $B as $A's upstream only when $A and $B shares the same name, and "git -c push.default=simple" on branch $A would push to update the branch $A at the remote $B came from. Also more places use the sole remote, if exists, before defaulting to 'origin'. * tk/simple-autosetupmerge: push: new config option "push.autoSetupRemote" supports "simple" push push: default to single remote even when not named origin branch: new autosetupmerge option 'simple' for matching branches
Diffstat (limited to 'branch.c')
-rw-r--r--branch.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/branch.c b/branch.c
index bde705b..2d6569b 100644
--- a/branch.c
+++ b/branch.c
@@ -44,9 +44,9 @@ static int find_tracked_branch(struct remote *remote, void *priv)
string_list_clear(tracking->srcs, 0);
break;
}
+ /* remote_find_tracking() searches by src if present */
tracking->spec.src = NULL;
}
-
return 0;
}
@@ -264,15 +264,23 @@ static void setup_tracking(const char *new_ref, const char *orig_ref,
if (!tracking.matches)
switch (track) {
+ /* If ref is not remote, still use local */
case BRANCH_TRACK_ALWAYS:
case BRANCH_TRACK_EXPLICIT:
case BRANCH_TRACK_OVERRIDE:
+ /* Remote matches not evaluated */
case BRANCH_TRACK_INHERIT:
break;
+ /* Otherwise, if no remote don't track */
default:
goto cleanup;
}
+ /*
+ * This check does not apply to BRANCH_TRACK_INHERIT;
+ * that supports multiple entries in tracking_srcs but
+ * leaves tracking.matches at 0.
+ */
if (tracking.matches > 1) {
int status = die_message(_("not tracking: ambiguous information for ref '%s'"),
orig_ref);
@@ -307,6 +315,21 @@ static void setup_tracking(const char *new_ref, const char *orig_ref,
exit(status);
}
+ if (track == BRANCH_TRACK_SIMPLE) {
+ /*
+ * Only track if remote branch name matches.
+ * Reaching into items[0].string is safe because
+ * we know there is at least one and not more than
+ * one entry (because only BRANCH_TRACK_INHERIT can
+ * produce more than one entry).
+ */
+ const char *tracked_branch;
+ if (!skip_prefix(tracking.srcs->items[0].string,
+ "refs/heads/", &tracked_branch) ||
+ strcmp(tracked_branch, new_ref))
+ return;
+ }
+
if (tracking.srcs->nr < 1)
string_list_append(tracking.srcs, orig_ref);
if (install_branch_config_multiple_remotes(config_flags, new_ref,
@@ -603,6 +626,8 @@ static int submodule_create_branch(struct repository *r,
/* Default for "git checkout". Do not pass --track. */
case BRANCH_TRACK_REMOTE:
/* Default for "git branch". Do not pass --track. */
+ case BRANCH_TRACK_SIMPLE:
+ /* Config-driven only. Do not pass --track. */
break;
}