+
Skip to content

branch: Move multiple branches in a single --force #1992

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Documentation/git-branch.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ git branch [--color[=<when>] | --no-color] [--show-current]
[(-r|--remotes) | (-a|--all)]
[--list] [<pattern>...]
git branch [--track[=(direct|inherit)] | --no-track] [-f]
[--recurse-submodules] <branch-name> [<start-point>]
[--recurse-submodules] <branch-name>... [<start-point>]
git branch (--set-upstream-to=<upstream>|-u <upstream>) [<branch-name>]
git branch --unset-upstream [<branch-name>]
git branch (-m|-M) [<old-branch>] <new-branch>
Expand Down
26 changes: 14 additions & 12 deletions builtin/branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

static const char * const builtin_branch_usage[] = {
N_("git branch [<options>] [-r | -a] [--merged] [--no-merged]"),
N_("git branch [<options>] [-f] [--recurse-submodules] <branch-name> [<start-point>]"),
N_("git branch [<options>] [-f] [--recurse-submodules] <branch-name>... [<start-point>]"),
N_("git branch [<options>] [-l] [<pattern>...]"),
N_("git branch [<options>] [-r] (-d | -D) <branch-name>..."),
N_("git branch [<options>] (-m | -M) [<old-branch>] <new-branch>"),
Expand Down Expand Up @@ -992,9 +992,9 @@ int cmd_branch(int argc,
strbuf_addf(&buf, "branch.%s.merge", branch->name);
git_config_set_multivar(buf.buf, NULL, NULL, CONFIG_FLAGS_MULTI_REPLACE);
strbuf_release(&buf);
} else if (!noncreate_actions && argc > 0 && argc <= 2) {
const char *branch_name = argv[0];
const char *start_name = argc == 2 ? argv[1] : head;
} else if (!noncreate_actions && argc > 0) {
const char *start_name = argc == 1 ? head : argv[argc - 1];
int iters = argc == 1 ? 1 : argc - 1;

if (filter.kind != FILTER_REFS_BRANCHES)
die(_("the -a, and -r, options to 'git branch' do not take a branch name.\n"
Expand All @@ -1003,15 +1003,17 @@ int cmd_branch(int argc,
if (track == BRANCH_TRACK_OVERRIDE)
die(_("the '--set-upstream' option is no longer supported. Please use '--track' or '--set-upstream-to' instead"));

if (recurse_submodules) {
create_branches_recursively(the_repository, branch_name,
start_name, NULL, force,
reflog, quiet, track, 0);
ret = 0;
goto out;
for (int i = 0; i < iters; i++) {
const char *branch_name = argv[i];

if (recurse_submodules)
create_branches_recursively(the_repository, branch_name,
start_name, NULL, force,
reflog, quiet, track, 0);
else
create_branch(the_repository, branch_name, start_name, force, 0,
reflog, quiet, track, 0);
}
create_branch(the_repository, branch_name, start_name, force, 0,
reflog, quiet, track, 0);
} else
usage_with_options(builtin_branch_usage, options);

Expand Down
7 changes: 7 additions & 0 deletions t/t3200-branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ test_expect_success 'git branch --force abc should succeed when abc exists' '
test_cmp expect actual
'

test_expect_success 'git branch --force br1 br2 abc should create 2 new branches' '
git branch --force br1 br2 abc &&
test_ref_exists refs/heads/br1 &&
test_ref_exists refs/heads/br2 &&
git branch -d br1 br2
'

test_expect_success 'git branch a/b/c should create a branch' '
git branch a/b/c &&
test_ref_exists refs/heads/a/b/c
Expand Down
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载