| 636 | } |
| 637 | |
| 638 | static int checkout(int submodule_progress, |
| 639 | struct list_objects_filter_options *filter_options, |
| 640 | int filter_submodules, |
| 641 | enum ref_storage_format ref_storage_format) |
| 642 | { |
| 643 | struct object_id oid; |
| 644 | char *head; |
| 645 | struct lock_file lock_file = LOCK_INIT; |
| 646 | struct unpack_trees_options opts; |
| 647 | struct tree *tree; |
| 648 | struct tree_desc t; |
| 649 | int err = 0; |
| 650 | struct run_hooks_opt hook_opt = RUN_HOOKS_OPT_INIT_FORCE_SERIAL; |
| 651 | |
| 652 | if (option_no_checkout) |
| 653 | return 0; |
| 654 | |
| 655 | head = refs_resolve_refdup(get_main_ref_store(the_repository), "HEAD", |
| 656 | RESOLVE_REF_READING, &oid, NULL); |
| 657 | if (!head) { |
| 658 | warning(_("remote HEAD refers to nonexistent ref, " |
| 659 | "unable to checkout")); |
| 660 | return 0; |
| 661 | } |
| 662 | if (!strcmp(head, "HEAD")) { |
| 663 | if (advice_enabled(ADVICE_DETACHED_HEAD)) |
| 664 | detach_advice(oid_to_hex(&oid)); |
| 665 | FREE_AND_NULL(head); |
| 666 | } else { |
| 667 | if (!starts_with(head, "refs/heads/")) |
| 668 | die(_("HEAD not found below refs/heads!")); |
| 669 | } |
| 670 | |
| 671 | /* We need to be in the new work tree for the checkout */ |
| 672 | setup_work_tree(the_repository); |
| 673 | |
| 674 | repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR); |
| 675 | |
| 676 | memset(&opts, 0, sizeof opts); |
| 677 | opts.update = 1; |
| 678 | opts.merge = 1; |
| 679 | opts.clone = 1; |
| 680 | opts.preserve_ignored = 0; |
| 681 | opts.fn = oneway_merge; |
| 682 | opts.verbose_update = (option_verbosity >= 0); |
| 683 | opts.src_index = the_repository->index; |
| 684 | opts.dst_index = the_repository->index; |
| 685 | init_checkout_metadata(&opts.meta, head, &oid, NULL); |
| 686 | |
| 687 | tree = repo_parse_tree_indirect(the_repository, &oid); |
| 688 | if (!tree) |
| 689 | die(_("unable to parse commit %s"), oid_to_hex(&oid)); |
| 690 | if (repo_parse_tree(the_repository, tree) < 0) |
| 691 | exit(128); |
| 692 | init_tree_desc(&t, &tree->object.oid, tree->buffer, tree->size); |
| 693 | if (unpack_trees(1, &t, &opts) < 0) |
| 694 | die(_("unable to checkout working tree")); |
| 695 |
no test coverage detected