Skip to content

Commit

Permalink
checkout: relocate --to's "no branch specified" check
Browse files Browse the repository at this point in the history
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 <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Eric Sunshine authored and Junio C Hamano committed Jul 6, 2015
1 parent c990a4c commit 9559ce8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions builtin/checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -865,8 +865,6 @@ static int prepare_linked_checkout(const struct checkout_opts *opts,
int counter = 0, len, ret;
unsigned char rev[20];

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

Expand Down Expand Up @@ -1303,8 +1301,11 @@ static int checkout_branch(struct checkout_opts *opts,
free(head_ref);
}

if (opts->new_worktree)
if (opts->new_worktree) {
if (!new->commit)
die(_("no branch specified"));
return prepare_linked_checkout(opts, new);
}

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

0 comments on commit 9559ce8

Please sign in to comment.