{"thread":{"id":"19383","subject":"[buglet] misleading error message from git checkout","startedAt":"2009-05-16T10:25:31Z","lastAt":"2009-05-17T02:43:08Z","messageCount":4,"participants":["Nanako Shiraishi","Daniel Cordero","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"114091","messageId":"20090516192531.6117@nanako3.lavabit.com","threadId":"19383","inReplyTo":null,"subject":"[buglet] misleading error message from git checkout","fromName":"Nanako Shiraishi","fromEmail":"nanako3@lavabit.com","sentAt":"2009-05-16T10:25:31Z","receivedAt":"2009-05-16T10:25:31Z","isPatch":false,"sender":{"key":"nanako3@lavabit.com","avatar":"https://gravatar.com/avatar/3777b9e201c5883a62b1a6fdf7c53f2d712d1d80989146063ea861e33aad72a8?d=mp&s=160"},"body":"When you aren't on any branch, have changes in your working files, and try to switch to another branch, you get an error message like this:\n\n % git checkout another\n Previous HEAD position was 0beee4c... git-add--interactive: remove hunk coalescing\n error: You have local changes to 'git-add--interactive.perl'; cannot switch branches.\n\nBecause the first line says \"Previous ... was\", I was mislead to believe that I sucsessfully switched branches, but I was mistaken.\n\nIf git-checkout were still a shell script probably I would have looked into fixing this myself, but now it is rewritten in C... Can somebody fix this please?\n\n-- \nNanako Shiraishi\nhttp://ivory.ap.teacup.com/nanako3/\n"},{"id":"114109","messageId":"20090516175444.GA1000@cumin.applehq.eu","threadId":"19383","inReplyTo":"20090516192531.6117@nanako3.lavabit.com","subject":"[PATCH] builtin-checkout: Don't tell user that HEAD has moved before it has","fromName":"Daniel Cordero","fromEmail":"theappleman@gmail.com","sentAt":"2009-05-16T17:54:45Z","receivedAt":"2009-05-16T17:54:45Z","isPatch":true,"sender":{"key":"theappleman@gmail.com","avatar":null},"body":"Previously, checkout would tell the user this message before moving HEAD,\nwithout regard to whether the upcoming move will result in success.\nIf the move failed, this causes confusion.\n\nShow the message after the move, unless the move failed.\n\nSigned-off-by: Daniel Cordero <theappleman@gmail.com>\n---\n builtin-checkout.c |   16 ++++++++--------\n 1 files changed, 8 insertions(+), 8 deletions(-)\n\ndiff --git a/builtin-checkout.c b/builtin-checkout.c\nindex dc4bfb5..f2d7ef0 100644\n--- a/builtin-checkout.c\n+++ b/builtin-checkout.c\n@@ -541,14 +541,6 @@ static int switch_branches(struct checkout_opts *opts, struct branch_info *new)\n \t\tparse_commit(new->commit);\n \t}\n \n-\t/*\n-\t * If we were on a detached HEAD, but we are now moving to\n-\t * a new commit, we want to mention the old commit once more\n-\t * to remind the user that it might be lost.\n-\t */\n-\tif (!opts->quiet && !old.path && old.commit && new->commit != old.commit)\n-\t\tdescribe_detached_head(\"Previous HEAD position was\", old.commit);\n-\n \tif (!old.commit && !opts->force) {\n \t\tif (!opts->quiet) {\n \t\t\twarning(\"You appear to be on a branch yet to be born.\");\n@@ -561,6 +553,14 @@ static int switch_branches(struct checkout_opts *opts, struct branch_info *new)\n \tif (ret)\n \t\treturn ret;\n \n+\t/*\n+\t * If we were on a detached HEAD, but have now moved to\n+\t * a new commit, we want to mention the old commit once more\n+\t * to remind the user that it might be lost.\n+\t */\n+\tif (!opts->quiet && !old.path && old.commit && new->commit != old.commit)\n+\t\tdescribe_detached_head(\"Previous HEAD position was\", old.commit);\n+\n \tupdate_refs_for_switch(opts, &old, new);\n \n \tret = post_checkout_hook(old.commit, new->commit, 1);\n-- \n1.6.3.1.93.g8d138\n"},{"id":"114118","messageId":"7vr5yolt1j.fsf@alter.siamese.dyndns.org","threadId":"19383","inReplyTo":"20090516175444.GA1000@cumin.applehq.eu","subject":"Re: [PATCH] builtin-checkout: Don't tell user that HEAD has moved before it has","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-05-16T19:57:44Z","receivedAt":"2009-05-16T19:57:44Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Daniel Cordero <theappleman@gmail.com> writes:\n\n> Previously, checkout would tell the user this message before moving HEAD,\n> without regard to whether the upcoming move will result in success.\n> If the move failed, this causes confusion.\n>\n> Show the message after the move, unless the move failed.\n>\n> Signed-off-by: Daniel Cordero <theappleman@gmail.com>\n\nThanks; the patch looks obviously good.  Can we have tests?\n"},{"id":"114120","messageId":"20090517114308.6117@nanako3.lavabit.com","threadId":"19383","inReplyTo":"7vr5yolt1j.fsf@alter.siamese.dyndns.org","subject":"[PATCH] test: checkout shouldn't say that HEAD has moved if it didn't","fromName":"Nanako Shiraishi","fromEmail":"nanako3@lavabit.com","sentAt":"2009-05-17T02:43:08Z","receivedAt":"2009-05-17T02:43:08Z","isPatch":true,"sender":{"key":"nanako3@lavabit.com","avatar":"https://gravatar.com/avatar/3777b9e201c5883a62b1a6fdf7c53f2d712d1d80989146063ea861e33aad72a8?d=mp&s=160"},"body":"Signed-off-by: しらいしななこ <nanako3@lavabit.com>\n---\n\nQuoting Junio C Hamano <gitster@pobox.com>:\n\n> Daniel Cordero <theappleman@gmail.com> writes:\n>\n>> Previously, checkout would tell the user this message before moving HEAD,\n>> without regard to whether the upcoming move will result in success.\n>> If the move failed, this causes confusion.\n>>\n>> Show the message after the move, unless the move failed.\n>>\n>> Signed-off-by: Daniel Cordero <theappleman@gmail.com>\n>\n> Thanks; the patch looks obviously good.  Can we have tests?\n\nHere is one.\n\n t/t7201-co.sh |    8 ++++++++\n 1 files changed, 8 insertions(+), 0 deletions(-)\n\ndiff --git a/t/t7201-co.sh b/t/t7201-co.sh\nindex bdb808a..ebfd34d 100755\n--- a/t/t7201-co.sh\n+++ b/t/t7201-co.sh\n@@ -534,4 +534,12 @@ test_expect_success 'failing checkout -b should not break working tree' '\n \n '\n \n+test_expect_success 'switch out of non-branch' '\n+\tgit reset --hard master &&\n+\tgit checkout master^0 &&\n+\techo modified >one &&\n+\ttest_must_fail git checkout renamer 2>error.log &&\n+\t! grep \"^Previous HEAD\" error.log\n+'\n+\n test_done\n\n-- \nNanako Shiraishi\nhttp://ivory.ap.teacup.com/nanako3/\n"}]}