Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2019-04-25 10:41:14 +0300
committerJunio C Hamano <gitster@pobox.com>2019-04-25 10:41:14 +0300
commit4a3ed2bec6031545aea38db10e443a979951346f (patch)
treedbb5ba4597bdd046ac9ed9dc0e57a7de9250a636 /builtin/checkout.c
parentb72e90712eb0e802b232ad4c88460d04279c7111 (diff)
parent6eff409e8a760645ae5357d1e95e7e7ff3c04456 (diff)
Merge branch 'nd/checkout-m'
"git checkout -m <other>" was about carrying the differences between HEAD and the working-tree files forward while checking out another branch, and ignored the differences between HEAD and the index. The command has been taught to abort when the index and the HEAD are different. * nd/checkout-m: checkout: prevent losing staged changes with --merge read-tree: add --quiet unpack-trees: rename "gently" flag to "quiet" unpack-trees: keep gently check inside add_rejected_path
Diffstat (limited to 'builtin/checkout.c')
-rw-r--r--builtin/checkout.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 2e72a5e5a9..ffa776c6e1 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -700,7 +700,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) {
@@ -725,6 +725,7 @@ 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;
@@ -737,6 +738,12 @@ 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),
@@ -781,7 +788,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
ret = merge_trees(&o,
get_commit_tree(new_branch_info->commit),
work,
- get_commit_tree(old_branch_info->commit),
+ old_tree,
&result);
if (ret < 0)
exit(128);