Git 2.23
[gitweb.git] / builtin / checkout.c
index 824ab65886c0f5778be250331174ee13b1c67b6f..6123f732a2c84f975c576e7077a0c6da369e6b31 100644 (file)
@@ -454,9 +454,11 @@ static int checkout_paths(const struct checkout_opts *opts,
                        patch_mode = "--patch=checkout";
                else if (opts->checkout_index && !opts->checkout_worktree)
                        patch_mode = "--patch=reset";
+               else if (!opts->checkout_index && opts->checkout_worktree)
+                       patch_mode = "--patch=worktree";
                else
-                       die(_("'%s' with only '%s' is not currently supported"),
-                           "--patch", "--worktree");
+                       BUG("either flag must have been set, worktree=%d, index=%d",
+                           opts->checkout_worktree, opts->checkout_index);
                return run_add_interactive(revision, patch_mode, &opts->pathspec);
        }
 
@@ -483,7 +485,7 @@ static int checkout_paths(const struct checkout_opts *opts,
                                                        ps_matched,
                                                        opts);
 
-       if (report_path_error(ps_matched, &opts->pathspec, opts->prefix)) {
+       if (report_path_error(ps_matched, &opts->pathspec)) {
                free(ps_matched);
                return 1;
        }
@@ -682,7 +684,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
                topts.initial_checkout = is_cache_unborn();
                topts.update = 1;
                topts.merge = 1;
-               topts.gently = opts->merge && old_branch_info->commit;
+               topts.quiet = opts->merge && old_branch_info->commit;
                topts.verbose_update = opts->show_progress;
                topts.fn = twoway_merge;
                if (opts->overwrite_ignore) {
@@ -708,7 +710,10 @@ static int merge_working_tree(const struct checkout_opts *opts,
                         */
                        struct tree *result;
                        struct tree *work;
+                       struct tree *old_tree;
                        struct merge_options o;
+                       struct strbuf sb = STRBUF_INIT;
+
                        if (!opts->merge)
                                return 1;
 
@@ -718,6 +723,19 @@ static int merge_working_tree(const struct checkout_opts *opts,
                         */
                        if (!old_branch_info->commit)
                                return 1;
+                       old_tree = get_commit_tree(old_branch_info->commit);
+
+                       if (repo_index_has_changes(the_repository, old_tree, &sb))
+                               die(_("cannot continue with staged changes in "
+                                     "the following files:\n%s"), sb.buf);
+                       strbuf_release(&sb);
+
+                       if (repo_index_has_changes(the_repository,
+                                                  get_commit_tree(old_branch_info->commit),
+                                                  &sb))
+                               warning(_("staged changes in the following files may be lost: %s"),
+                                       sb.buf);
+                       strbuf_release(&sb);
 
                        /* Do more real merge */
 
@@ -755,7 +773,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
                        ret = merge_trees(&o,
                                          new_tree,
                                          work,
-                                         get_commit_tree(old_branch_info->commit),
+                                         old_tree,
                                          &result);
                        if (ret < 0)
                                exit(128);
@@ -1324,9 +1342,7 @@ static void die_if_some_operation_in_progress(void)
                      "Consider \"git revert --quit\" "
                      "or \"git worktree add\"."));
        if (state.bisect_in_progress)
-               die(_("cannot switch branch while bisecting\n"
-                     "Consider \"git bisect reset HEAD\" "
-                     "or \"git worktree add\"."));
+               warning(_("you are switching branch while bisecting"));
 }
 
 static int checkout_branch(struct checkout_opts *opts,
@@ -1753,7 +1769,7 @@ int cmd_restore(int argc, const char **argv, const char *prefix)
        struct option *options;
        struct option restore_options[] = {
                OPT_STRING('s', "source", &opts.from_treeish, "<tree-ish>",
-                          N_("where the checkout from")),
+                          N_("which tree-ish to checkout from")),
                OPT_BOOL('S', "staged", &opts.checkout_index,
                           N_("restore the index")),
                OPT_BOOL('W', "worktree", &opts.checkout_worktree,