checkout: relocate --to's "no branch specified" check
[gitweb.git] / builtin / checkout.c
index 5ada22a39084f3a301115e7091100a51965ae51c..162c822263a7988e223b4bae654d61c2c6e2e641 100644 (file)
@@ -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);
 
@@ -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];