aboutsummaryrefslogtreecommitdiff
path: root/builtin-checkout.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2008-09-07 19:49:25 -0700
committerJunio C Hamano <gitster@pobox.com>2008-09-09 22:55:22 -0700
commit5521883490e85f4d973141972cf16f89a79f1979 (patch)
tree650ba77fc5225db197582c4adb7eac754059b698 /builtin-checkout.c
parentaaefbfa66c348a461b3081873ef42819c8b38dac (diff)
downloadgit-5521883490e85f4d973141972cf16f89a79f1979.tar.gz
git-5521883490e85f4d973141972cf16f89a79f1979.tar.xz
checkout: do not lose staged removal
The logic to checkout a different commit implements the safety to never lose user's local changes. For example, switching from a commit to another commit, when you have changed a path that is different between them, need to merge your changes to the version from the switched-to commit, which you may not necessarily be able to resolve easily. By default, "git checkout" refused to switch branches, to give you a chance to stash your local changes (or use "-m" to merge, accepting the risks of getting conflicts). This safety, however, had one deliberate hole since early June 2005. When your local change was to remove a path (and optionally to stage that removal), the command checked out the path from the switched-to commit nevertheless. This was to allow an initial checkout to happen smoothly (e.g. an initial checkout is done by starting with an empty index and switching from the commit at the HEAD to the same commit). We can tighten the rule slightly to allow this special case to pass, without losing sight of removal explicitly done by the user, by noticing if the index is truly empty when the operation begins. For historical background, see: http://thread.gmane.org/gmane.comp.version-control.git/4641/focus=4646 This case is marked as *0* in the message, which both Linus and I said "it feels somewhat wrong but otherwise we cannot start from an empty index". Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-checkout.c')
-rw-r--r--builtin-checkout.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/builtin-checkout.c b/builtin-checkout.c
index f6f8f086d..774f29992 100644
--- a/builtin-checkout.c
+++ b/builtin-checkout.c
@@ -242,6 +242,8 @@ static int merge_working_tree(struct checkout_opts *opts,
}
/* 2-way merge to the new branch */
+ topts.initial_checkout = (!active_nr &&
+ (old->commit == new->commit));
topts.update = 1;
topts.merge = 1;
topts.gently = opts->merge;