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
This commit is contained in:
27
branch.c
27
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user