From: Junio C Hamano Date: Thu, 25 Apr 2019 07:41:14 +0000 (+0900) Subject: Merge branch 'nd/checkout-m' X-Git-Tag: v2.22.0-rc0~66 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4a3ed2bec6031545aea38db10e443a979951346f;p=thirdparty%2Fgit.git Merge branch 'nd/checkout-m' "git checkout -m " 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 --- 4a3ed2bec6031545aea38db10e443a979951346f diff --cc builtin/checkout.c index 2e72a5e5a9,7cd01f62be..ffa776c6e1 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@@ -737,14 -738,13 +738,20 @@@ static int merge_working_tree(const str */ 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 */ /*