1#include"builtin.h" 2#include"config.h" 3#include"checkout.h" 4#include"lockfile.h" 5#include"parse-options.h" 6#include"refs.h" 7#include"object-store.h" 8#include"commit.h" 9#include"tree.h" 10#include"tree-walk.h" 11#include"cache-tree.h" 12#include"unpack-trees.h" 13#include"dir.h" 14#include"run-command.h" 15#include"merge-recursive.h" 16#include"branch.h" 17#include"diff.h" 18#include"revision.h" 19#include"remote.h" 20#include"blob.h" 21#include"xdiff-interface.h" 22#include"ll-merge.h" 23#include"resolve-undo.h" 24#include"submodule-config.h" 25#include"submodule.h" 26#include"advice.h" 27 28static int checkout_optimize_new_branch; 29 30static const char*const checkout_usage[] = { 31N_("git checkout [<options>] <branch>"), 32N_("git checkout [<options>] [<branch>] -- <file>..."), 33 NULL, 34}; 35 36struct checkout_opts { 37int patch_mode; 38int quiet; 39int merge; 40int force; 41int force_detach; 42int writeout_stage; 43int overwrite_ignore; 44int ignore_skipworktree; 45int ignore_other_worktrees; 46int show_progress; 47int count_checkout_paths; 48/* 49 * If new checkout options are added, skip_merge_working_tree 50 * should be updated accordingly. 51 */ 52 53const char*new_branch; 54const char*new_branch_force; 55const char*new_orphan_branch; 56int new_branch_log; 57enum branch_track track; 58struct diff_options diff_options; 59 60int branch_exists; 61const char*prefix; 62struct pathspec pathspec; 63struct tree *source_tree; 64}; 65 66static intpost_checkout_hook(struct commit *old_commit,struct commit *new_commit, 67int changed) 68{ 69returnrun_hook_le(NULL,"post-checkout", 70oid_to_hex(old_commit ? &old_commit->object.oid : &null_oid), 71oid_to_hex(new_commit ? &new_commit->object.oid : &null_oid), 72 changed ?"1":"0", NULL); 73/* "new_commit" can be NULL when checking out from the index before 74 a commit exists. */ 75 76} 77 78static intupdate_some(const struct object_id *oid,struct strbuf *base, 79const char*pathname,unsigned mode,int stage,void*context) 80{ 81int len; 82struct cache_entry *ce; 83int pos; 84 85if(S_ISDIR(mode)) 86return READ_TREE_RECURSIVE; 87 88 len = base->len +strlen(pathname); 89 ce =make_empty_cache_entry(&the_index, len); 90oidcpy(&ce->oid, oid); 91memcpy(ce->name, base->buf, base->len); 92memcpy(ce->name + base->len, pathname, len - base->len); 93 ce->ce_flags =create_ce_flags(0) | CE_UPDATE; 94 ce->ce_namelen = len; 95 ce->ce_mode =create_ce_mode(mode); 96 97/* 98 * If the entry is the same as the current index, we can leave the old 99 * entry in place. Whether it is UPTODATE or not, checkout_entry will 100 * do the right thing. 101 */ 102 pos =cache_name_pos(ce->name, ce->ce_namelen); 103if(pos >=0) { 104struct cache_entry *old = active_cache[pos]; 105if(ce->ce_mode == old->ce_mode && 106oideq(&ce->oid, &old->oid)) { 107 old->ce_flags |= CE_UPDATE; 108discard_cache_entry(ce); 109return0; 110} 111} 112 113add_cache_entry(ce, ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE); 114return0; 115} 116 117static intread_tree_some(struct tree *tree,const struct pathspec *pathspec) 118{ 119read_tree_recursive(tree,"",0,0, pathspec, update_some, NULL); 120 121/* update the index with the given tree's info 122 * for all args, expanding wildcards, and exit 123 * with any non-zero return code. 124 */ 125return0; 126} 127 128static intskip_same_name(const struct cache_entry *ce,int pos) 129{ 130while(++pos < active_nr && 131!strcmp(active_cache[pos]->name, ce->name)) 132;/* skip */ 133return pos; 134} 135 136static intcheck_stage(int stage,const struct cache_entry *ce,int pos) 137{ 138while(pos < active_nr && 139!strcmp(active_cache[pos]->name, ce->name)) { 140if(ce_stage(active_cache[pos]) == stage) 141return0; 142 pos++; 143} 144if(stage ==2) 145returnerror(_("path '%s' does not have our version"), ce->name); 146else 147returnerror(_("path '%s' does not have their version"), ce->name); 148} 149 150static intcheck_stages(unsigned stages,const struct cache_entry *ce,int pos) 151{ 152unsigned seen =0; 153const char*name = ce->name; 154 155while(pos < active_nr) { 156 ce = active_cache[pos]; 157if(strcmp(name, ce->name)) 158break; 159 seen |= (1<<ce_stage(ce)); 160 pos++; 161} 162if((stages & seen) != stages) 163returnerror(_("path '%s' does not have all necessary versions"), 164 name); 165return0; 166} 167 168static intcheckout_stage(int stage,const struct cache_entry *ce,int pos, 169const struct checkout *state,int*nr_checkouts) 170{ 171while(pos < active_nr && 172!strcmp(active_cache[pos]->name, ce->name)) { 173if(ce_stage(active_cache[pos]) == stage) 174returncheckout_entry(active_cache[pos], state, 175 NULL, nr_checkouts); 176 pos++; 177} 178if(stage ==2) 179returnerror(_("path '%s' does not have our version"), ce->name); 180else 181returnerror(_("path '%s' does not have their version"), ce->name); 182} 183 184static intcheckout_merged(int pos,const struct checkout *state,int*nr_checkouts) 185{ 186struct cache_entry *ce = active_cache[pos]; 187const char*path = ce->name; 188 mmfile_t ancestor, ours, theirs; 189int status; 190struct object_id oid; 191 mmbuffer_t result_buf; 192struct object_id threeway[3]; 193unsigned mode =0; 194 195memset(threeway,0,sizeof(threeway)); 196while(pos < active_nr) { 197int stage; 198 stage =ce_stage(ce); 199if(!stage ||strcmp(path, ce->name)) 200break; 201oidcpy(&threeway[stage -1], &ce->oid); 202if(stage ==2) 203 mode =create_ce_mode(ce->ce_mode); 204 pos++; 205 ce = active_cache[pos]; 206} 207if(is_null_oid(&threeway[1]) ||is_null_oid(&threeway[2])) 208returnerror(_("path '%s' does not have necessary versions"), path); 209 210read_mmblob(&ancestor, &threeway[0]); 211read_mmblob(&ours, &threeway[1]); 212read_mmblob(&theirs, &threeway[2]); 213 214/* 215 * NEEDSWORK: re-create conflicts from merges with 216 * merge.renormalize set, too 217 */ 218 status =ll_merge(&result_buf, path, &ancestor,"base", 219&ours,"ours", &theirs,"theirs", 220 state->istate, NULL); 221free(ancestor.ptr); 222free(ours.ptr); 223free(theirs.ptr); 224if(status <0|| !result_buf.ptr) { 225free(result_buf.ptr); 226returnerror(_("path '%s': cannot merge"), path); 227} 228 229/* 230 * NEEDSWORK: 231 * There is absolutely no reason to write this as a blob object 232 * and create a phony cache entry. This hack is primarily to get 233 * to the write_entry() machinery that massages the contents to 234 * work-tree format and writes out which only allows it for a 235 * cache entry. The code in write_entry() needs to be refactored 236 * to allow us to feed a <buffer, size, mode> instead of a cache 237 * entry. Such a refactoring would help merge_recursive as well 238 * (it also writes the merge result to the object database even 239 * when it may contain conflicts). 240 */ 241if(write_object_file(result_buf.ptr, result_buf.size, blob_type, &oid)) 242die(_("Unable to add merge result for '%s'"), path); 243free(result_buf.ptr); 244 ce =make_transient_cache_entry(mode, &oid, path,2); 245if(!ce) 246die(_("make_cache_entry failed for path '%s'"), path); 247 status =checkout_entry(ce, state, NULL, nr_checkouts); 248discard_cache_entry(ce); 249return status; 250} 251 252static intcheckout_paths(const struct checkout_opts *opts, 253const char*revision) 254{ 255int pos; 256struct checkout state = CHECKOUT_INIT; 257static char*ps_matched; 258struct object_id rev; 259struct commit *head; 260int errs =0; 261struct lock_file lock_file = LOCK_INIT; 262int nr_checkouts =0, nr_unmerged =0; 263 264if(opts->track != BRANCH_TRACK_UNSPECIFIED) 265die(_("'%s' cannot be used with updating paths"),"--track"); 266 267if(opts->new_branch_log) 268die(_("'%s' cannot be used with updating paths"),"-l"); 269 270if(opts->force && opts->patch_mode) 271die(_("'%s' cannot be used with updating paths"),"-f"); 272 273if(opts->force_detach) 274die(_("'%s' cannot be used with updating paths"),"--detach"); 275 276if(opts->merge && opts->patch_mode) 277die(_("'%s' cannot be used with%s"),"--merge","--patch"); 278 279if(opts->force && opts->merge) 280die(_("'%s' cannot be used with%s"),"-f","-m"); 281 282if(opts->new_branch) 283die(_("Cannot update paths and switch to branch '%s' at the same time."), 284 opts->new_branch); 285 286if(opts->patch_mode) 287returnrun_add_interactive(revision,"--patch=checkout", 288&opts->pathspec); 289 290hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR); 291if(read_cache_preload(&opts->pathspec) <0) 292returnerror(_("index file corrupt")); 293 294if(opts->source_tree) 295read_tree_some(opts->source_tree, &opts->pathspec); 296 297 ps_matched =xcalloc(opts->pathspec.nr,1); 298 299/* 300 * Make sure all pathspecs participated in locating the paths 301 * to be checked out. 302 */ 303for(pos =0; pos < active_nr; pos++) { 304struct cache_entry *ce = active_cache[pos]; 305 ce->ce_flags &= ~CE_MATCHED; 306if(!opts->ignore_skipworktree &&ce_skip_worktree(ce)) 307continue; 308if(opts->source_tree && !(ce->ce_flags & CE_UPDATE)) 309/* 310 * "git checkout tree-ish -- path", but this entry 311 * is in the original index; it will not be checked 312 * out to the working tree and it does not matter 313 * if pathspec matched this entry. We will not do 314 * anything to this entry at all. 315 */ 316continue; 317/* 318 * Either this entry came from the tree-ish we are 319 * checking the paths out of, or we are checking out 320 * of the index. 321 * 322 * If it comes from the tree-ish, we already know it 323 * matches the pathspec and could just stamp 324 * CE_MATCHED to it from update_some(). But we still 325 * need ps_matched and read_tree_recursive (and 326 * eventually tree_entry_interesting) cannot fill 327 * ps_matched yet. Once it can, we can avoid calling 328 * match_pathspec() for _all_ entries when 329 * opts->source_tree != NULL. 330 */ 331if(ce_path_match(&the_index, ce, &opts->pathspec, ps_matched)) 332 ce->ce_flags |= CE_MATCHED; 333} 334 335if(report_path_error(ps_matched, &opts->pathspec, opts->prefix)) { 336free(ps_matched); 337return1; 338} 339free(ps_matched); 340 341/* "checkout -m path" to recreate conflicted state */ 342if(opts->merge) 343unmerge_marked_index(&the_index); 344 345/* Any unmerged paths? */ 346for(pos =0; pos < active_nr; pos++) { 347const struct cache_entry *ce = active_cache[pos]; 348if(ce->ce_flags & CE_MATCHED) { 349if(!ce_stage(ce)) 350continue; 351if(opts->force) { 352warning(_("path '%s' is unmerged"), ce->name); 353}else if(opts->writeout_stage) { 354 errs |=check_stage(opts->writeout_stage, ce, pos); 355}else if(opts->merge) { 356 errs |=check_stages((1<<2) | (1<<3), ce, pos); 357}else{ 358 errs =1; 359error(_("path '%s' is unmerged"), ce->name); 360} 361 pos =skip_same_name(ce, pos) -1; 362} 363} 364if(errs) 365return1; 366 367/* Now we are committed to check them out */ 368 state.force =1; 369 state.refresh_cache =1; 370 state.istate = &the_index; 371 372enable_delayed_checkout(&state); 373for(pos =0; pos < active_nr; pos++) { 374struct cache_entry *ce = active_cache[pos]; 375if(ce->ce_flags & CE_MATCHED) { 376if(!ce_stage(ce)) { 377 errs |=checkout_entry(ce, &state, 378 NULL, &nr_checkouts); 379continue; 380} 381if(opts->writeout_stage) 382 errs |=checkout_stage(opts->writeout_stage, 383 ce, pos, 384&state, &nr_checkouts); 385else if(opts->merge) 386 errs |=checkout_merged(pos, &state, 387&nr_unmerged); 388 pos =skip_same_name(ce, pos) -1; 389} 390} 391 errs |=finish_delayed_checkout(&state, &nr_checkouts); 392 393if(opts->count_checkout_paths) { 394if(nr_unmerged) 395fprintf_ln(stderr,Q_("Recreated%dmerge conflict", 396"Recreated%dmerge conflicts", 397 nr_unmerged), 398 nr_unmerged); 399if(opts->source_tree) 400fprintf_ln(stderr,Q_("Updated%dpath from%s", 401"Updated%dpaths from%s", 402 nr_checkouts), 403 nr_checkouts, 404find_unique_abbrev(&opts->source_tree->object.oid, 405 DEFAULT_ABBREV)); 406else if(!nr_unmerged || nr_checkouts) 407fprintf_ln(stderr,Q_("Updated%dpath from the index", 408"Updated%dpaths from the index", 409 nr_checkouts), 410 nr_checkouts); 411} 412 413if(write_locked_index(&the_index, &lock_file, COMMIT_LOCK)) 414die(_("unable to write new index file")); 415 416read_ref_full("HEAD",0, &rev, NULL); 417 head =lookup_commit_reference_gently(the_repository, &rev,1); 418 419 errs |=post_checkout_hook(head, head,0); 420return errs; 421} 422 423static voidshow_local_changes(struct object *head, 424const struct diff_options *opts) 425{ 426struct rev_info rev; 427/* I think we want full paths, even if we're in a subdirectory. */ 428repo_init_revisions(the_repository, &rev, NULL); 429 rev.diffopt.flags = opts->flags; 430 rev.diffopt.output_format |= DIFF_FORMAT_NAME_STATUS; 431diff_setup_done(&rev.diffopt); 432add_pending_object(&rev, head, NULL); 433run_diff_index(&rev,0); 434} 435 436static voiddescribe_detached_head(const char*msg,struct commit *commit) 437{ 438struct strbuf sb = STRBUF_INIT; 439 440if(!parse_commit(commit)) 441pp_commit_easy(CMIT_FMT_ONELINE, commit, &sb); 442if(print_sha1_ellipsis()) { 443fprintf(stderr,"%s %s...%s\n", msg, 444find_unique_abbrev(&commit->object.oid, DEFAULT_ABBREV), sb.buf); 445}else{ 446fprintf(stderr,"%s %s %s\n", msg, 447find_unique_abbrev(&commit->object.oid, DEFAULT_ABBREV), sb.buf); 448} 449strbuf_release(&sb); 450} 451 452static intreset_tree(struct tree *tree,const struct checkout_opts *o, 453int worktree,int*writeout_error) 454{ 455struct unpack_trees_options opts; 456struct tree_desc tree_desc; 457 458memset(&opts,0,sizeof(opts)); 459 opts.head_idx = -1; 460 opts.update = worktree; 461 opts.skip_unmerged = !worktree; 462 opts.reset =1; 463 opts.merge =1; 464 opts.fn = oneway_merge; 465 opts.verbose_update = o->show_progress; 466 opts.src_index = &the_index; 467 opts.dst_index = &the_index; 468parse_tree(tree); 469init_tree_desc(&tree_desc, tree->buffer, tree->size); 470switch(unpack_trees(1, &tree_desc, &opts)) { 471case-2: 472*writeout_error =1; 473/* 474 * We return 0 nevertheless, as the index is all right 475 * and more importantly we have made best efforts to 476 * update paths in the work tree, and we cannot revert 477 * them. 478 */ 479/* fallthrough */ 480case0: 481return0; 482default: 483return128; 484} 485} 486 487struct branch_info { 488const char*name;/* The short name used */ 489const char*path;/* The full name of a real branch */ 490struct commit *commit;/* The named commit */ 491/* 492 * if not null the branch is detached because it's already 493 * checked out in this checkout 494 */ 495char*checkout; 496}; 497 498static voidsetup_branch_path(struct branch_info *branch) 499{ 500struct strbuf buf = STRBUF_INIT; 501 502strbuf_branchname(&buf, branch->name, INTERPRET_BRANCH_LOCAL); 503if(strcmp(buf.buf, branch->name)) 504 branch->name =xstrdup(buf.buf); 505strbuf_splice(&buf,0,0,"refs/heads/",11); 506 branch->path =strbuf_detach(&buf, NULL); 507} 508 509/* 510 * Skip merging the trees, updating the index and working directory if and 511 * only if we are creating a new branch via "git checkout -b <new_branch>." 512 */ 513static intskip_merge_working_tree(const struct checkout_opts *opts, 514const struct branch_info *old_branch_info, 515const struct branch_info *new_branch_info) 516{ 517/* 518 * Do the merge if sparse checkout is on and the user has not opted in 519 * to the optimized behavior 520 */ 521if(core_apply_sparse_checkout && !checkout_optimize_new_branch) 522return0; 523 524/* 525 * We must do the merge if we are actually moving to a new commit. 526 */ 527if(!old_branch_info->commit || !new_branch_info->commit || 528!oideq(&old_branch_info->commit->object.oid, 529&new_branch_info->commit->object.oid)) 530return0; 531 532/* 533 * opts->patch_mode cannot be used with switching branches so is 534 * not tested here 535 */ 536 537/* 538 * opts->quiet only impacts output so doesn't require a merge 539 */ 540 541/* 542 * Honor the explicit request for a three-way merge or to throw away 543 * local changes 544 */ 545if(opts->merge || opts->force) 546return0; 547 548/* 549 * --detach is documented as "updating the index and the files in the 550 * working tree" but this optimization skips those steps so fall through 551 * to the regular code path. 552 */ 553if(opts->force_detach) 554return0; 555 556/* 557 * opts->writeout_stage cannot be used with switching branches so is 558 * not tested here 559 */ 560 561/* 562 * Honor the explicit ignore requests 563 */ 564if(!opts->overwrite_ignore || opts->ignore_skipworktree || 565 opts->ignore_other_worktrees) 566return0; 567 568/* 569 * opts->show_progress only impacts output so doesn't require a merge 570 */ 571 572/* 573 * If we aren't creating a new branch any changes or updates will 574 * happen in the existing branch. Since that could only be updating 575 * the index and working directory, we don't want to skip those steps 576 * or we've defeated any purpose in running the command. 577 */ 578if(!opts->new_branch) 579return0; 580 581/* 582 * new_branch_force is defined to "create/reset and checkout a branch" 583 * so needs to go through the merge to do the reset 584 */ 585if(opts->new_branch_force) 586return0; 587 588/* 589 * A new orphaned branch requrires the index and the working tree to be 590 * adjusted to <start_point> 591 */ 592if(opts->new_orphan_branch) 593return0; 594 595/* 596 * Remaining variables are not checkout options but used to track state 597 */ 598 599return1; 600} 601 602static intmerge_working_tree(const struct checkout_opts *opts, 603struct branch_info *old_branch_info, 604struct branch_info *new_branch_info, 605int*writeout_error) 606{ 607int ret; 608struct lock_file lock_file = LOCK_INIT; 609 610hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR); 611if(read_cache_preload(NULL) <0) 612returnerror(_("index file corrupt")); 613 614resolve_undo_clear(); 615if(opts->force) { 616 ret =reset_tree(get_commit_tree(new_branch_info->commit), 617 opts,1, writeout_error); 618if(ret) 619return ret; 620}else{ 621struct tree_desc trees[2]; 622struct tree *tree; 623struct unpack_trees_options topts; 624 625memset(&topts,0,sizeof(topts)); 626 topts.head_idx = -1; 627 topts.src_index = &the_index; 628 topts.dst_index = &the_index; 629 630setup_unpack_trees_porcelain(&topts,"checkout"); 631 632refresh_cache(REFRESH_QUIET); 633 634if(unmerged_cache()) { 635error(_("you need to resolve your current index first")); 636return1; 637} 638 639/* 2-way merge to the new branch */ 640 topts.initial_checkout =is_cache_unborn(); 641 topts.update =1; 642 topts.merge =1; 643 topts.gently = opts->merge && old_branch_info->commit; 644 topts.verbose_update = opts->show_progress; 645 topts.fn = twoway_merge; 646if(opts->overwrite_ignore) { 647 topts.dir =xcalloc(1,sizeof(*topts.dir)); 648 topts.dir->flags |= DIR_SHOW_IGNORED; 649setup_standard_excludes(topts.dir); 650} 651 tree =parse_tree_indirect(old_branch_info->commit ? 652&old_branch_info->commit->object.oid : 653 the_hash_algo->empty_tree); 654init_tree_desc(&trees[0], tree->buffer, tree->size); 655 tree =parse_tree_indirect(&new_branch_info->commit->object.oid); 656init_tree_desc(&trees[1], tree->buffer, tree->size); 657 658 ret =unpack_trees(2, trees, &topts); 659clear_unpack_trees_porcelain(&topts); 660if(ret == -1) { 661/* 662 * Unpack couldn't do a trivial merge; either 663 * give up or do a real merge, depending on 664 * whether the merge flag was used. 665 */ 666struct tree *result; 667struct tree *work; 668struct merge_options o; 669if(!opts->merge) 670return1; 671 672/* 673 * Without old_branch_info->commit, the below is the same as 674 * the two-tree unpack we already tried and failed. 675 */ 676if(!old_branch_info->commit) 677return1; 678 679/* Do more real merge */ 680 681/* 682 * We update the index fully, then write the 683 * tree from the index, then merge the new 684 * branch with the current tree, with the old 685 * branch as the base. Then we reset the index 686 * (but not the working tree) to the new 687 * branch, leaving the working tree as the 688 * merged version, but skipping unmerged 689 * entries in the index. 690 */ 691 692add_files_to_cache(NULL, NULL,0); 693/* 694 * NEEDSWORK: carrying over local changes 695 * when branches have different end-of-line 696 * normalization (or clean+smudge rules) is 697 * a pain; plumb in an option to set 698 * o.renormalize? 699 */ 700init_merge_options(&o); 701 o.verbosity =0; 702 work =write_tree_from_memory(&o); 703 704 ret =reset_tree(get_commit_tree(new_branch_info->commit), 705 opts,1, 706 writeout_error); 707if(ret) 708return ret; 709 o.ancestor = old_branch_info->name; 710 o.branch1 = new_branch_info->name; 711 o.branch2 ="local"; 712 ret =merge_trees(&o, 713get_commit_tree(new_branch_info->commit), 714 work, 715get_commit_tree(old_branch_info->commit), 716&result); 717if(ret <0) 718exit(128); 719 ret =reset_tree(get_commit_tree(new_branch_info->commit), 720 opts,0, 721 writeout_error); 722strbuf_release(&o.obuf); 723if(ret) 724return ret; 725} 726} 727 728if(!active_cache_tree) 729 active_cache_tree =cache_tree(); 730 731if(!cache_tree_fully_valid(active_cache_tree)) 732cache_tree_update(&the_index, WRITE_TREE_SILENT | WRITE_TREE_REPAIR); 733 734if(write_locked_index(&the_index, &lock_file, COMMIT_LOCK)) 735die(_("unable to write new index file")); 736 737if(!opts->force && !opts->quiet) 738show_local_changes(&new_branch_info->commit->object, &opts->diff_options); 739 740return0; 741} 742 743static voidreport_tracking(struct branch_info *new_branch_info) 744{ 745struct strbuf sb = STRBUF_INIT; 746struct branch *branch =branch_get(new_branch_info->name); 747 748if(!format_tracking_info(branch, &sb, AHEAD_BEHIND_FULL)) 749return; 750fputs(sb.buf, stdout); 751strbuf_release(&sb); 752} 753 754static voidupdate_refs_for_switch(const struct checkout_opts *opts, 755struct branch_info *old_branch_info, 756struct branch_info *new_branch_info) 757{ 758struct strbuf msg = STRBUF_INIT; 759const char*old_desc, *reflog_msg; 760if(opts->new_branch) { 761if(opts->new_orphan_branch) { 762char*refname; 763 764 refname =mkpathdup("refs/heads/%s", opts->new_orphan_branch); 765if(opts->new_branch_log && 766!should_autocreate_reflog(refname)) { 767int ret; 768struct strbuf err = STRBUF_INIT; 769 770 ret =safe_create_reflog(refname,1, &err); 771if(ret) { 772fprintf(stderr,_("Can not do reflog for '%s':%s\n"), 773 opts->new_orphan_branch, err.buf); 774strbuf_release(&err); 775free(refname); 776return; 777} 778strbuf_release(&err); 779} 780free(refname); 781} 782else 783create_branch(opts->new_branch, new_branch_info->name, 784 opts->new_branch_force ?1:0, 785 opts->new_branch_force ?1:0, 786 opts->new_branch_log, 787 opts->quiet, 788 opts->track); 789 new_branch_info->name = opts->new_branch; 790setup_branch_path(new_branch_info); 791} 792 793 old_desc = old_branch_info->name; 794if(!old_desc && old_branch_info->commit) 795 old_desc =oid_to_hex(&old_branch_info->commit->object.oid); 796 797 reflog_msg =getenv("GIT_REFLOG_ACTION"); 798if(!reflog_msg) 799strbuf_addf(&msg,"checkout: moving from%sto%s", 800 old_desc ? old_desc :"(invalid)", new_branch_info->name); 801else 802strbuf_insert(&msg,0, reflog_msg,strlen(reflog_msg)); 803 804if(!strcmp(new_branch_info->name,"HEAD") && !new_branch_info->path && !opts->force_detach) { 805/* Nothing to do. */ 806}else if(opts->force_detach || !new_branch_info->path) {/* No longer on any branch. */ 807update_ref(msg.buf,"HEAD", &new_branch_info->commit->object.oid, NULL, 808 REF_NO_DEREF, UPDATE_REFS_DIE_ON_ERR); 809if(!opts->quiet) { 810if(old_branch_info->path && 811 advice_detached_head && !opts->force_detach) 812detach_advice(new_branch_info->name); 813describe_detached_head(_("HEAD is now at"), new_branch_info->commit); 814} 815}else if(new_branch_info->path) {/* Switch branches. */ 816if(create_symref("HEAD", new_branch_info->path, msg.buf) <0) 817die(_("unable to update HEAD")); 818if(!opts->quiet) { 819if(old_branch_info->path && !strcmp(new_branch_info->path, old_branch_info->path)) { 820if(opts->new_branch_force) 821fprintf(stderr,_("Reset branch '%s'\n"), 822 new_branch_info->name); 823else 824fprintf(stderr,_("Already on '%s'\n"), 825 new_branch_info->name); 826}else if(opts->new_branch) { 827if(opts->branch_exists) 828fprintf(stderr,_("Switched to and reset branch '%s'\n"), new_branch_info->name); 829else 830fprintf(stderr,_("Switched to a new branch '%s'\n"), new_branch_info->name); 831}else{ 832fprintf(stderr,_("Switched to branch '%s'\n"), 833 new_branch_info->name); 834} 835} 836if(old_branch_info->path && old_branch_info->name) { 837if(!ref_exists(old_branch_info->path) &&reflog_exists(old_branch_info->path)) 838delete_reflog(old_branch_info->path); 839} 840} 841remove_branch_state(); 842strbuf_release(&msg); 843if(!opts->quiet && 844(new_branch_info->path || (!opts->force_detach && !strcmp(new_branch_info->name,"HEAD")))) 845report_tracking(new_branch_info); 846} 847 848static intadd_pending_uninteresting_ref(const char*refname, 849const struct object_id *oid, 850int flags,void*cb_data) 851{ 852add_pending_oid(cb_data, refname, oid, UNINTERESTING); 853return0; 854} 855 856static voiddescribe_one_orphan(struct strbuf *sb,struct commit *commit) 857{ 858strbuf_addstr(sb," "); 859strbuf_add_unique_abbrev(sb, &commit->object.oid, DEFAULT_ABBREV); 860strbuf_addch(sb,' '); 861if(!parse_commit(commit)) 862pp_commit_easy(CMIT_FMT_ONELINE, commit, sb); 863strbuf_addch(sb,'\n'); 864} 865 866#define ORPHAN_CUTOFF 4 867static voidsuggest_reattach(struct commit *commit,struct rev_info *revs) 868{ 869struct commit *c, *last = NULL; 870struct strbuf sb = STRBUF_INIT; 871int lost =0; 872while((c =get_revision(revs)) != NULL) { 873if(lost < ORPHAN_CUTOFF) 874describe_one_orphan(&sb, c); 875 last = c; 876 lost++; 877} 878if(ORPHAN_CUTOFF < lost) { 879int more = lost - ORPHAN_CUTOFF; 880if(more ==1) 881describe_one_orphan(&sb, last); 882else 883strbuf_addf(&sb,_(" ... and%dmore.\n"), more); 884} 885 886fprintf(stderr, 887Q_( 888/* The singular version */ 889"Warning: you are leaving%dcommit behind, " 890"not connected to\n" 891"any of your branches:\n\n" 892"%s\n", 893/* The plural version */ 894"Warning: you are leaving%dcommits behind, " 895"not connected to\n" 896"any of your branches:\n\n" 897"%s\n", 898/* Give ngettext() the count */ 899 lost), 900 lost, 901 sb.buf); 902strbuf_release(&sb); 903 904if(advice_detached_head) 905fprintf(stderr, 906Q_( 907/* The singular version */ 908"If you want to keep it by creating a new branch, " 909"this may be a good time\nto do so with:\n\n" 910" git branch <new-branch-name>%s\n\n", 911/* The plural version */ 912"If you want to keep them by creating a new branch, " 913"this may be a good time\nto do so with:\n\n" 914" git branch <new-branch-name>%s\n\n", 915/* Give ngettext() the count */ 916 lost), 917find_unique_abbrev(&commit->object.oid, DEFAULT_ABBREV)); 918} 919 920/* 921 * We are about to leave commit that was at the tip of a detached 922 * HEAD. If it is not reachable from any ref, this is the last chance 923 * for the user to do so without resorting to reflog. 924 */ 925static voidorphaned_commit_warning(struct commit *old_commit,struct commit *new_commit) 926{ 927struct rev_info revs; 928struct object *object = &old_commit->object; 929 930repo_init_revisions(the_repository, &revs, NULL); 931setup_revisions(0, NULL, &revs, NULL); 932 933 object->flags &= ~UNINTERESTING; 934add_pending_object(&revs, object,oid_to_hex(&object->oid)); 935 936for_each_ref(add_pending_uninteresting_ref, &revs); 937add_pending_oid(&revs,"HEAD", &new_commit->object.oid, UNINTERESTING); 938 939if(prepare_revision_walk(&revs)) 940die(_("internal error in revision walk")); 941if(!(old_commit->object.flags & UNINTERESTING)) 942suggest_reattach(old_commit, &revs); 943else 944describe_detached_head(_("Previous HEAD position was"), old_commit); 945 946/* Clean up objects used, as they will be reused. */ 947clear_commit_marks_all(ALL_REV_FLAGS); 948} 949 950static intswitch_branches(const struct checkout_opts *opts, 951struct branch_info *new_branch_info) 952{ 953int ret =0; 954struct branch_info old_branch_info; 955void*path_to_free; 956struct object_id rev; 957int flag, writeout_error =0; 958memset(&old_branch_info,0,sizeof(old_branch_info)); 959 old_branch_info.path = path_to_free =resolve_refdup("HEAD",0, &rev, &flag); 960if(old_branch_info.path) 961 old_branch_info.commit =lookup_commit_reference_gently(the_repository, &rev,1); 962if(!(flag & REF_ISSYMREF)) 963 old_branch_info.path = NULL; 964 965if(old_branch_info.path) 966skip_prefix(old_branch_info.path,"refs/heads/", &old_branch_info.name); 967 968if(!new_branch_info->name) { 969 new_branch_info->name ="HEAD"; 970 new_branch_info->commit = old_branch_info.commit; 971if(!new_branch_info->commit) 972die(_("You are on a branch yet to be born")); 973parse_commit_or_die(new_branch_info->commit); 974} 975 976/* optimize the "checkout -b <new_branch> path */ 977if(skip_merge_working_tree(opts, &old_branch_info, new_branch_info)) { 978if(!checkout_optimize_new_branch && !opts->quiet) { 979if(read_cache_preload(NULL) <0) 980returnerror(_("index file corrupt")); 981show_local_changes(&new_branch_info->commit->object, &opts->diff_options); 982} 983}else{ 984 ret =merge_working_tree(opts, &old_branch_info, new_branch_info, &writeout_error); 985if(ret) { 986free(path_to_free); 987return ret; 988} 989} 990 991if(!opts->quiet && !old_branch_info.path && old_branch_info.commit && new_branch_info->commit != old_branch_info.commit) 992orphaned_commit_warning(old_branch_info.commit, new_branch_info->commit); 993 994update_refs_for_switch(opts, &old_branch_info, new_branch_info); 995 996 ret =post_checkout_hook(old_branch_info.commit, new_branch_info->commit,1); 997free(path_to_free); 998return ret || writeout_error; 999}10001001static intgit_checkout_config(const char*var,const char*value,void*cb)1002{1003if(!strcmp(var,"checkout.optimizenewbranch")) {1004 checkout_optimize_new_branch =git_config_bool(var, value);1005return0;1006}10071008if(!strcmp(var,"diff.ignoresubmodules")) {1009struct checkout_opts *opts = cb;1010handle_ignore_submodules_arg(&opts->diff_options, value);1011return0;1012}10131014if(starts_with(var,"submodule."))1015returngit_default_submodule_config(var, value, NULL);10161017returngit_xmerge_config(var, value, NULL);1018}10191020static intparse_branchname_arg(int argc,const char**argv,1021int dwim_new_local_branch_ok,1022struct branch_info *new_branch_info,1023struct checkout_opts *opts,1024struct object_id *rev,1025int*dwim_remotes_matched)1026{1027struct tree **source_tree = &opts->source_tree;1028const char**new_branch = &opts->new_branch;1029int argcount =0;1030struct object_id branch_rev;1031const char*arg;1032int dash_dash_pos;1033int has_dash_dash =0;1034int i;10351036/*1037 * case 1: git checkout <ref> -- [<paths>]1038 *1039 * <ref> must be a valid tree, everything after the '--' must be1040 * a path.1041 *1042 * case 2: git checkout -- [<paths>]1043 *1044 * everything after the '--' must be paths.1045 *1046 * case 3: git checkout <something> [--]1047 *1048 * (a) If <something> is a commit, that is to1049 * switch to the branch or detach HEAD at it. As a special case,1050 * if <something> is A...B (missing A or B means HEAD but you can1051 * omit at most one side), and if there is a unique merge base1052 * between A and B, A...B names that merge base.1053 *1054 * (b) If <something> is _not_ a commit, either "--" is present1055 * or <something> is not a path, no -t or -b was given, and1056 * and there is a tracking branch whose name is <something>1057 * in one and only one remote (or if the branch exists on the1058 * remote named in checkout.defaultRemote), then this is a1059 * short-hand to fork local <something> from that1060 * remote-tracking branch.1061 *1062 * (c) Otherwise, if "--" is present, treat it like case (1).1063 *1064 * (d) Otherwise :1065 * - if it's a reference, treat it like case (1)1066 * - else if it's a path, treat it like case (2)1067 * - else: fail.1068 *1069 * case 4: git checkout <something> <paths>1070 *1071 * The first argument must not be ambiguous.1072 * - If it's *only* a reference, treat it like case (1).1073 * - If it's only a path, treat it like case (2).1074 * - else: fail.1075 *1076 */1077if(!argc)1078return0;10791080 arg = argv[0];1081 dash_dash_pos = -1;1082for(i =0; i < argc; i++) {1083if(!strcmp(argv[i],"--")) {1084 dash_dash_pos = i;1085break;1086}1087}1088if(dash_dash_pos ==0)1089return1;/* case (2) */1090else if(dash_dash_pos ==1)1091 has_dash_dash =1;/* case (3) or (1) */1092else if(dash_dash_pos >=2)1093die(_("only one reference expected,%dgiven."), dash_dash_pos);1094 opts->count_checkout_paths = !opts->quiet && !has_dash_dash;10951096if(!strcmp(arg,"-"))1097 arg ="@{-1}";10981099if(get_oid_mb(arg, rev)) {1100/*1101 * Either case (3) or (4), with <something> not being1102 * a commit, or an attempt to use case (1) with an1103 * invalid ref.1104 *1105 * It's likely an error, but we need to find out if1106 * we should auto-create the branch, case (3).(b).1107 */1108int recover_with_dwim = dwim_new_local_branch_ok;11091110if(!has_dash_dash &&1111(check_filename(opts->prefix, arg) || !no_wildcard(arg)))1112 recover_with_dwim =0;1113/*1114 * Accept "git checkout foo" and "git checkout foo --"1115 * as candidates for dwim.1116 */1117if(!(argc ==1&& !has_dash_dash) &&1118!(argc ==2&& has_dash_dash))1119 recover_with_dwim =0;11201121if(recover_with_dwim) {1122const char*remote =unique_tracking_name(arg, rev,1123 dwim_remotes_matched);1124if(remote) {1125*new_branch = arg;1126 arg = remote;1127/* DWIMmed to create local branch, case (3).(b) */1128}else{1129 recover_with_dwim =0;1130}1131}11321133if(!recover_with_dwim) {1134if(has_dash_dash)1135die(_("invalid reference:%s"), arg);1136return argcount;1137}1138}11391140/* we can't end up being in (2) anymore, eat the argument */1141 argcount++;1142 argv++;1143 argc--;11441145 new_branch_info->name = arg;1146setup_branch_path(new_branch_info);11471148if(!check_refname_format(new_branch_info->path,0) &&1149!read_ref(new_branch_info->path, &branch_rev))1150oidcpy(rev, &branch_rev);1151else1152 new_branch_info->path = NULL;/* not an existing branch */11531154 new_branch_info->commit =lookup_commit_reference_gently(the_repository, rev,1);1155if(!new_branch_info->commit) {1156/* not a commit */1157*source_tree =parse_tree_indirect(rev);1158}else{1159parse_commit_or_die(new_branch_info->commit);1160*source_tree =get_commit_tree(new_branch_info->commit);1161}11621163if(!*source_tree)/* case (1): want a tree */1164die(_("reference is not a tree:%s"), arg);1165if(!has_dash_dash) {/* case (3).(d) -> (1) */1166/*1167 * Do not complain the most common case1168 * git checkout branch1169 * even if there happen to be a file called 'branch';1170 * it would be extremely annoying.1171 */1172if(argc)1173verify_non_filename(opts->prefix, arg);1174}else{1175 argcount++;1176 argv++;1177 argc--;1178}11791180return argcount;1181}11821183static intswitch_unborn_to_new_branch(const struct checkout_opts *opts)1184{1185int status;1186struct strbuf branch_ref = STRBUF_INIT;11871188if(!opts->new_branch)1189die(_("You are on a branch yet to be born"));1190strbuf_addf(&branch_ref,"refs/heads/%s", opts->new_branch);1191 status =create_symref("HEAD", branch_ref.buf,"checkout -b");1192strbuf_release(&branch_ref);1193if(!opts->quiet)1194fprintf(stderr,_("Switched to a new branch '%s'\n"),1195 opts->new_branch);1196return status;1197}11981199static intcheckout_branch(struct checkout_opts *opts,1200struct branch_info *new_branch_info)1201{1202if(opts->pathspec.nr)1203die(_("paths cannot be used with switching branches"));12041205if(opts->patch_mode)1206die(_("'%s' cannot be used with switching branches"),1207"--patch");12081209if(opts->writeout_stage)1210die(_("'%s' cannot be used with switching branches"),1211"--ours/--theirs");12121213if(opts->force && opts->merge)1214die(_("'%s' cannot be used with '%s'"),"-f","-m");12151216if(opts->force_detach && opts->new_branch)1217die(_("'%s' cannot be used with '%s'"),1218"--detach","-b/-B/--orphan");12191220if(opts->new_orphan_branch) {1221if(opts->track != BRANCH_TRACK_UNSPECIFIED)1222die(_("'%s' cannot be used with '%s'"),"--orphan","-t");1223}else if(opts->force_detach) {1224if(opts->track != BRANCH_TRACK_UNSPECIFIED)1225die(_("'%s' cannot be used with '%s'"),"--detach","-t");1226}else if(opts->track == BRANCH_TRACK_UNSPECIFIED)1227 opts->track = git_branch_track;12281229if(new_branch_info->name && !new_branch_info->commit)1230die(_("Cannot switch branch to a non-commit '%s'"),1231 new_branch_info->name);12321233if(new_branch_info->path && !opts->force_detach && !opts->new_branch &&1234!opts->ignore_other_worktrees) {1235int flag;1236char*head_ref =resolve_refdup("HEAD",0, NULL, &flag);1237if(head_ref &&1238(!(flag & REF_ISSYMREF) ||strcmp(head_ref, new_branch_info->path)))1239die_if_checked_out(new_branch_info->path,1);1240free(head_ref);1241}12421243if(!new_branch_info->commit && opts->new_branch) {1244struct object_id rev;1245int flag;12461247if(!read_ref_full("HEAD",0, &rev, &flag) &&1248(flag & REF_ISSYMREF) &&is_null_oid(&rev))1249returnswitch_unborn_to_new_branch(opts);1250}1251returnswitch_branches(opts, new_branch_info);1252}12531254intcmd_checkout(int argc,const char**argv,const char*prefix)1255{1256struct checkout_opts opts;1257struct branch_info new_branch_info;1258char*conflict_style = NULL;1259int dwim_new_local_branch =1;1260int dwim_remotes_matched =0;1261struct option options[] = {1262OPT__QUIET(&opts.quiet,N_("suppress progress reporting")),1263OPT_STRING('b', NULL, &opts.new_branch,N_("branch"),1264N_("create and checkout a new branch")),1265OPT_STRING('B', NULL, &opts.new_branch_force,N_("branch"),1266N_("create/reset and checkout a branch")),1267OPT_BOOL('l', NULL, &opts.new_branch_log,N_("create reflog for new branch")),1268OPT_BOOL(0,"detach", &opts.force_detach,N_("detach HEAD at named commit")),1269OPT_SET_INT('t',"track", &opts.track,N_("set upstream info for new branch"),1270 BRANCH_TRACK_EXPLICIT),1271OPT_STRING(0,"orphan", &opts.new_orphan_branch,N_("new-branch"),N_("new unparented branch")),1272OPT_SET_INT_F('2',"ours", &opts.writeout_stage,1273N_("checkout our version for unmerged files"),12742, PARSE_OPT_NONEG),1275OPT_SET_INT_F('3',"theirs", &opts.writeout_stage,1276N_("checkout their version for unmerged files"),12773, PARSE_OPT_NONEG),1278OPT__FORCE(&opts.force,N_("force checkout (throw away local modifications)"),1279 PARSE_OPT_NOCOMPLETE),1280OPT_BOOL('m',"merge", &opts.merge,N_("perform a 3-way merge with the new branch")),1281OPT_BOOL_F(0,"overwrite-ignore", &opts.overwrite_ignore,1282N_("update ignored files (default)"),1283 PARSE_OPT_NOCOMPLETE),1284OPT_STRING(0,"conflict", &conflict_style,N_("style"),1285N_("conflict style (merge or diff3)")),1286OPT_BOOL('p',"patch", &opts.patch_mode,N_("select hunks interactively")),1287OPT_BOOL(0,"ignore-skip-worktree-bits", &opts.ignore_skipworktree,1288N_("do not limit pathspecs to sparse entries only")),1289OPT_HIDDEN_BOOL(0,"guess", &dwim_new_local_branch,1290N_("second guess 'git checkout <no-such-branch>'")),1291OPT_BOOL(0,"ignore-other-worktrees", &opts.ignore_other_worktrees,1292N_("do not check if another worktree is holding the given ref")),1293{ OPTION_CALLBACK,0,"recurse-submodules", NULL,1294"checkout","control recursive updating of submodules",1295 PARSE_OPT_OPTARG, option_parse_recurse_submodules_worktree_updater },1296OPT_BOOL(0,"progress", &opts.show_progress,N_("force progress reporting")),1297OPT_END(),1298};12991300memset(&opts,0,sizeof(opts));1301memset(&new_branch_info,0,sizeof(new_branch_info));1302 opts.overwrite_ignore =1;1303 opts.prefix = prefix;1304 opts.show_progress = -1;13051306git_config(git_checkout_config, &opts);13071308 opts.track = BRANCH_TRACK_UNSPECIFIED;13091310 argc =parse_options(argc, argv, prefix, options, checkout_usage,1311 PARSE_OPT_KEEP_DASHDASH);13121313if(opts.show_progress <0) {1314if(opts.quiet)1315 opts.show_progress =0;1316else1317 opts.show_progress =isatty(2);1318}13191320if(conflict_style) {1321 opts.merge =1;/* implied */1322git_xmerge_config("merge.conflictstyle", conflict_style, NULL);1323}13241325if((!!opts.new_branch + !!opts.new_branch_force + !!opts.new_orphan_branch) >1)1326die(_("-b, -B and --orphan are mutually exclusive"));13271328/*1329 * From here on, new_branch will contain the branch to be checked out,1330 * and new_branch_force and new_orphan_branch will tell us which one of1331 * -b/-B/--orphan is being used.1332 */1333if(opts.new_branch_force)1334 opts.new_branch = opts.new_branch_force;13351336if(opts.new_orphan_branch)1337 opts.new_branch = opts.new_orphan_branch;13381339/* --track without -b/-B/--orphan should DWIM */1340if(opts.track != BRANCH_TRACK_UNSPECIFIED && !opts.new_branch) {1341const char*argv0 = argv[0];1342if(!argc || !strcmp(argv0,"--"))1343die(_("--track needs a branch name"));1344skip_prefix(argv0,"refs/", &argv0);1345skip_prefix(argv0,"remotes/", &argv0);1346 argv0 =strchr(argv0,'/');1347if(!argv0 || !argv0[1])1348die(_("missing branch name; try -b"));1349 opts.new_branch = argv0 +1;1350}13511352/*1353 * Extract branch name from command line arguments, so1354 * all that is left is pathspecs.1355 *1356 * Handle1357 *1358 * 1) git checkout <tree> -- [<paths>]1359 * 2) git checkout -- [<paths>]1360 * 3) git checkout <something> [<paths>]1361 *1362 * including "last branch" syntax and DWIM-ery for names of1363 * remote branches, erroring out for invalid or ambiguous cases.1364 */1365if(argc) {1366struct object_id rev;1367int dwim_ok =1368!opts.patch_mode &&1369 dwim_new_local_branch &&1370 opts.track == BRANCH_TRACK_UNSPECIFIED &&1371!opts.new_branch;1372int n =parse_branchname_arg(argc, argv, dwim_ok,1373&new_branch_info, &opts, &rev,1374&dwim_remotes_matched);1375 argv += n;1376 argc -= n;1377}13781379if(argc) {1380parse_pathspec(&opts.pathspec,0,1381 opts.patch_mode ? PATHSPEC_PREFIX_ORIGIN :0,1382 prefix, argv);13831384if(!opts.pathspec.nr)1385die(_("invalid path specification"));13861387/*1388 * Try to give more helpful suggestion.1389 * new_branch && argc > 1 will be caught later.1390 */1391if(opts.new_branch && argc ==1)1392die(_("'%s' is not a commit and a branch '%s' cannot be created from it"),1393 argv[0], opts.new_branch);13941395if(opts.force_detach)1396die(_("git checkout: --detach does not take a path argument '%s'"),1397 argv[0]);13981399if(1< !!opts.writeout_stage + !!opts.force + !!opts.merge)1400die(_("git checkout: --ours/--theirs, --force and --merge are incompatible when\n"1401"checking out of the index."));1402}14031404if(opts.new_branch) {1405struct strbuf buf = STRBUF_INIT;14061407if(opts.new_branch_force)1408 opts.branch_exists =validate_branchname(opts.new_branch, &buf);1409else1410 opts.branch_exists =1411validate_new_branchname(opts.new_branch, &buf,0);1412strbuf_release(&buf);1413}14141415UNLEAK(opts);1416if(opts.patch_mode || opts.pathspec.nr) {1417int ret =checkout_paths(&opts, new_branch_info.name);1418if(ret && dwim_remotes_matched >1&&1419 advice_checkout_ambiguous_remote_branch_name)1420advise(_("'%s' matched more than one remote tracking branch.\n"1421"We found%dremotes with a reference that matched. So we fell back\n"1422"on trying to resolve the argument as a path, but failed there too!\n"1423"\n"1424"If you meant to check out a remote tracking branch on, e.g. 'origin',\n"1425"you can do so by fully qualifying the name with the --track option:\n"1426"\n"1427" git checkout --track origin/<name>\n"1428"\n"1429"If you'd like to always have checkouts of an ambiguous <name> prefer\n"1430"one remote, e.g. the 'origin' remote, consider setting\n"1431"checkout.defaultRemote=origin in your config."),1432 argv[0],1433 dwim_remotes_matched);1434return ret;1435}else{1436returncheckout_branch(&opts, &new_branch_info);1437}1438}