Skip to content

Commit 9559ce8

Browse files
sunshinecogitster
authored andcommitted
checkout: relocate --to's "no branch specified" check
The plan is to relocate "git checkout --to" functionality to "git worktree add", however, this check expects a 'struct branch_info' which git-worktree won't have at hand. It will, however, have access to its own command-line from which it can pick up the branch name. Therefore, as a preparatory step, rather than having prepare_linked_checkout() perform this check, make it the caller's responsibility. Signed-off-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c990a4c commit 9559ce8

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

builtin/checkout.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -865,8 +865,6 @@ static int prepare_linked_checkout(const struct checkout_opts *opts,
865865
int counter = 0, len, ret;
866866
unsigned char rev[20];
867867

868-
if (!new->commit)
869-
die(_("no branch specified"));
870868
if (file_exists(path) && !is_empty_dir(path))
871869
die(_("'%s' already exists"), path);
872870

@@ -1303,8 +1301,11 @@ static int checkout_branch(struct checkout_opts *opts,
13031301
free(head_ref);
13041302
}
13051303

1306-
if (opts->new_worktree)
1304+
if (opts->new_worktree) {
1305+
if (!new->commit)
1306+
die(_("no branch specified"));
13071307
return prepare_linked_checkout(opts, new);
1308+
}
13081309

13091310
if (!new->commit && opts->new_branch) {
13101311
unsigned char rev[20];

0 commit comments

Comments
 (0)