* Creates a branch in a submodule by calling * create_branches_recursively() in a child process. The child process * is necessary because install_branch_config_multiple_remotes() (which * is called by setup_tracking()) does not support writing configs to * submodules. */
| 667 | * submodules. |
| 668 | */ |
| 669 | static int submodule_create_branch(struct repository *r, |
| 670 | const struct submodule *submodule, |
| 671 | const char *name, const char *start_oid, |
| 672 | const char *tracking_name, int force, |
| 673 | int reflog, int quiet, |
| 674 | enum branch_track track, int dry_run) |
| 675 | { |
| 676 | int ret = 0; |
| 677 | struct child_process child = CHILD_PROCESS_INIT; |
| 678 | struct strbuf child_err = STRBUF_INIT; |
| 679 | struct strbuf out_buf = STRBUF_INIT; |
| 680 | char *out_prefix = xstrfmt("submodule '%s': ", submodule->name); |
| 681 | child.git_cmd = 1; |
| 682 | child.err = -1; |
| 683 | child.stdout_to_stderr = 1; |
| 684 | |
| 685 | prepare_other_repo_env(&child.env, r->gitdir); |
| 686 | /* |
| 687 | * submodule_create_branch() is indirectly invoked by "git |
| 688 | * branch", but we cannot invoke "git branch" in the child |
| 689 | * process. "git branch" accepts a branch name and start point, |
| 690 | * where the start point is assumed to provide both the OID |
| 691 | * (start_oid) and the branch to use for tracking |
| 692 | * (tracking_name). But when recursing through submodules, |
| 693 | * start_oid and tracking name need to be specified separately |
| 694 | * (see create_branches_recursively()). |
| 695 | */ |
| 696 | strvec_pushl(&child.args, "submodule--helper", "create-branch", NULL); |
| 697 | if (dry_run) |
| 698 | strvec_push(&child.args, "--dry-run"); |
| 699 | if (force) |
| 700 | strvec_push(&child.args, "--force"); |
| 701 | if (quiet) |
| 702 | strvec_push(&child.args, "--quiet"); |
| 703 | if (reflog) |
| 704 | strvec_push(&child.args, "--create-reflog"); |
| 705 | |
| 706 | switch (track) { |
| 707 | case BRANCH_TRACK_NEVER: |
| 708 | strvec_push(&child.args, "--no-track"); |
| 709 | break; |
| 710 | case BRANCH_TRACK_ALWAYS: |
| 711 | case BRANCH_TRACK_EXPLICIT: |
| 712 | strvec_push(&child.args, "--track=direct"); |
| 713 | break; |
| 714 | case BRANCH_TRACK_OVERRIDE: |
| 715 | BUG("BRANCH_TRACK_OVERRIDE cannot be used when creating a branch."); |
| 716 | break; |
| 717 | case BRANCH_TRACK_INHERIT: |
| 718 | strvec_push(&child.args, "--track=inherit"); |
| 719 | break; |
| 720 | case BRANCH_TRACK_UNSPECIFIED: |
| 721 | /* Default for "git checkout". Do not pass --track. */ |
| 722 | case BRANCH_TRACK_REMOTE: |
| 723 | /* Default for "git branch". Do not pass --track. */ |
| 724 | case BRANCH_TRACK_SIMPLE: |
| 725 | /* Config-driven only. Do not pass --track. */ |
| 726 | break; |
no test coverage detected