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 <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Sunshine committed Jul 6, 2015 at 13:30 UTC 9559ce8368b533862584b2717532e3c25232f1c9
1 file changed +4 -3
builtin/checkout.c
+4 -3
@@ -865,8 +865,6 @@ static int prepare_linked_checkout(const struct checkout_opts *opts,
865 int counter = 0, len, ret;
866 unsigned char rev[20];
867
868 - if (!new->commit)
869 - die(_("no branch specified"));
868 if (file_exists(path) && !is_empty_dir(path))
869 die(_("'%s' already exists"), path);
870
@@ -1303,8 +1301,11 @@ static int checkout_branch(struct checkout_opts *opts,
1301 free(head_ref);
1302 }
1303
1306 - if (opts->new_worktree)
1304 + if (opts->new_worktree) {
1305 + if (!new->commit)
1306 + die(_("no branch specified"));
1307 return prepare_linked_checkout(opts, new);
1308 + }
1309
1310 if (!new->commit && opts->new_branch) {
1311 unsigned char rev[20];