MCPcopy Create free account
hub / github.com/git/git / setup_tracking

Function setup_tracking

branch.c:252–351  ·  view source on GitHub ↗

* Used internally to set the branch. .{remote,merge} config * settings so that branch 'new_ref' tracks 'orig_ref'. Unlike * dwim_and_setup_tracking(), this does not do DWIM, i.e. "origin/main" * will not be expanded to "refs/remotes/origin/main", so it is not safe * for 'orig_ref' to be raw user input. */

Source from the content-addressed store, hash-verified

250 * for 'orig_ref' to be raw user input.
251 */
252static void setup_tracking(const char *new_ref, const char *orig_ref,
253 enum branch_track track, int quiet)
254{
255 struct tracking tracking;
256 struct string_list tracking_srcs = STRING_LIST_INIT_DUP;
257 int config_flags = quiet ? 0 : BRANCH_CONFIG_VERBOSE;
258 struct find_tracked_branch_cb ftb_cb = {
259 .tracking = &tracking,
260 .ambiguous_remotes = STRING_LIST_INIT_DUP,
261 };
262
263 if (!track)
264 BUG("asked to set up tracking, but tracking is disallowed");
265
266 memset(&tracking, 0, sizeof(tracking));
267 tracking.spec.dst = (char *)orig_ref;
268 tracking.srcs = &tracking_srcs;
269 if (track != BRANCH_TRACK_INHERIT)
270 for_each_remote(find_tracked_branch, &ftb_cb);
271 else if (inherit_tracking(&tracking, orig_ref))
272 goto cleanup;
273
274 if (!tracking.matches)
275 switch (track) {
276 /* If ref is not remote, still use local */
277 case BRANCH_TRACK_ALWAYS:
278 case BRANCH_TRACK_EXPLICIT:
279 case BRANCH_TRACK_OVERRIDE:
280 /* Remote matches not evaluated */
281 case BRANCH_TRACK_INHERIT:
282 break;
283 /* Otherwise, if no remote don't track */
284 default:
285 goto cleanup;
286 }
287
288 /*
289 * This check does not apply to BRANCH_TRACK_INHERIT;
290 * that supports multiple entries in tracking_srcs but
291 * leaves tracking.matches at 0.
292 */
293 if (tracking.matches > 1) {
294 int status = die_message(_("not tracking: ambiguous information for ref '%s'"),
295 orig_ref);
296 if (advice_enabled(ADVICE_AMBIGUOUS_FETCH_REFSPEC)) {
297 struct strbuf remotes_advice = STRBUF_INIT;
298 struct string_list_item *item;
299
300 for_each_string_list_item(item, &ftb_cb.ambiguous_remotes)
301 /*
302 * TRANSLATORS: This is a line listing a remote with duplicate
303 * refspecs in the advice message below. For RTL languages you'll
304 * probably want to swap the "%s" and leading " " space around.
305 */
306 strbuf_addf(&remotes_advice, _(" %s\n"), item->string);
307
308 /*
309 * TRANSLATORS: The second argument is a \n-delimited list of

Callers 3

create_branchFunction · 0.85
dwim_and_setup_trackingFunction · 0.85

Calls 10

for_each_remoteFunction · 0.85
inherit_trackingFunction · 0.85
die_messageFunction · 0.85
advice_enabledFunction · 0.85
strbuf_addfFunction · 0.85
adviseFunction · 0.85
strbuf_releaseFunction · 0.85
string_list_clearFunction · 0.85
string_list_appendFunction · 0.70

Tested by

no test coverage detected