{"thread":{"id":"19318","subject":"stage/commit issue when checking out a branch","startedAt":"2009-05-12T16:01:14Z","lastAt":"2009-05-12T16:56:56Z","messageCount":3,"participants":["Peter MacMillan","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"113649","messageId":"d96d20670905120901qa4c0353xc50160f880e17a21@mail.gmail.com","threadId":"19318","inReplyTo":null,"subject":"stage/commit issue when checking out a branch","fromName":"Peter MacMillan","fromEmail":"peterm@metavera.com","sentAt":"2009-05-12T16:01:14Z","receivedAt":"2009-05-12T16:01:14Z","isPatch":false,"sender":{"key":"peterm@metavera.com","avatar":null},"body":"Hello,\n\nI've run into a problem where staging changes, checking out a\ndifferent branch, and then commiting results in an empty commit.\n\nHere is a simplified reproduction of the problem:\n\ncurrently using 1.6.3, verified that it works correctly in git version 1.6.1.3.\n\nNew repo:\n\n$ mkdir bug\n$ cd bug\n$ git init\nInitialized empty Git repository in /home/peterm/bug/.git/\n\nNew file:\n\n$ echo \"Hello\" > FILE\n$ git add FILE\n$ git commit -m \"V1\"\n[master (root-commit) 5aeea22] V1\n 1 files changed, 1 insertions(+), 0 deletions(-)\n create mode 100644 FILE\n\nSimple change:\n\n$ echo \"Hello, world.\" > FILE\n$ git add FILE\n\nMove to a different branch:\n\n$ git checkout -b branch\nM\tFILE\nSwitched to a new branch 'branch'\n$ git status\n# On branch branch\n# Changes to be committed:\n#   (use \"git reset HEAD <file>...\" to unstage)\n#\n#\tmodified:   FILE\n#\n\nOh, still on the stage. Great. Commit!\n\n$ git commit -m \"V2\"\n[branch 818175e] V2\n$ git show HEAD\ncommit 818175efc55d2e23871541c5caa2fe771c825b73\nAuthor: Peter MacMillan <peterm@metavera.com>\nDate:   Tue May 12 11:38:02 2009 -0400\n\n    V2\n$ git status\n# On branch branch\n# Changes to be committed:\n#   (use \"git reset HEAD <file>...\" to unstage)\n#\n#\tmodified:   FILE\n#\n\nGuh? A few of us at the office have hit this and it used to work. The\nonly way to commit the stage is to reset to HEAD, re-add and then\ncommit.\n\nThanks for your help,\n\nPeter MacMillan <peterm@metavera.com>\n\nApplication Developer, Metavera Solutions Inc.\n502-2221 Yonge Street, Toronto, ON, M4S 2B4\n416-598-9300 x 27\n"},{"id":"113660","messageId":"7v8wl28ef3.fsf@alter.siamese.dyndns.org","threadId":"19318","inReplyTo":"d96d20670905120901qa4c0353xc50160f880e17a21@mail.gmail.com","subject":"Re: stage/commit issue when checking out a branch","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-05-12T16:38:24Z","receivedAt":"2009-05-12T16:38:24Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Sorry; broken as of v1.6.3~60; 83ae209 (checkout branch: prime cache-tree\nfully, 2009-04-20) is the culprit.\n"},{"id":"113666","messageId":"7v4ovq8dk7.fsf@alter.siamese.dyndns.org","threadId":"19318","inReplyTo":"d96d20670905120901qa4c0353xc50160f880e17a21@mail.gmail.com","subject":"[PATCH] Revert \"checkout branch: prime cache-tree fully\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-05-12T16:56:56Z","receivedAt":"2009-05-12T16:56:56Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"The logic in 83ae209 (checkout branch: prime cache-tree fully,\n2009-04-20) is bogus; checkout can switch branches with a dirty\nindex and in such a case the tree won't match HEAD.\n\nAdd t2014-switch to catch this breakage.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n builtin-checkout.c |    9 +--------\n t/t2014-switch.sh  |   28 ++++++++++++++++++++++++++++\n 2 files changed, 29 insertions(+), 8 deletions(-)\n create mode 100755 t/t2014-switch.sh\n\ndiff --git a/builtin-checkout.c b/builtin-checkout.c\nindex 15f0c32..dc4bfb5 100644\n--- a/builtin-checkout.c\n+++ b/builtin-checkout.c\n@@ -365,17 +365,14 @@ static int merge_working_tree(struct checkout_opts *opts,\n \tint ret;\n \tstruct lock_file *lock_file = xcalloc(1, sizeof(struct lock_file));\n \tint newfd = hold_locked_index(lock_file, 1);\n-\tint reprime_cache_tree = 0;\n \n \tif (read_cache() < 0)\n \t\treturn error(\"corrupt index file\");\n \n-\tcache_tree_free(&active_cache_tree);\n \tif (opts->force) {\n \t\tret = reset_tree(new->commit->tree, opts, 1);\n \t\tif (ret)\n \t\t\treturn ret;\n-\t\treprime_cache_tree = 1;\n \t} else {\n \t\tstruct tree_desc trees[2];\n \t\tstruct tree *tree;\n@@ -411,9 +408,7 @@ static int merge_working_tree(struct checkout_opts *opts,\n \t\tinit_tree_desc(&trees[1], tree->buffer, tree->size);\n \n \t\tret = unpack_trees(2, trees, &topts);\n-\t\tif (ret != -1) {\n-\t\t\treprime_cache_tree = 1;\n-\t\t} else {\n+\t\tif (ret == -1) {\n \t\t\t/*\n \t\t\t * Unpack couldn't do a trivial merge; either\n \t\t\t * give up or do a real merge, depending on\n@@ -457,8 +452,6 @@ static int merge_working_tree(struct checkout_opts *opts,\n \t\t}\n \t}\n \n-\tif (reprime_cache_tree)\n-\t\tprime_cache_tree(&active_cache_tree, new->commit->tree);\n \tif (write_cache(newfd, active_cache, active_nr) ||\n \t    commit_locked_index(lock_file))\n \t\tdie(\"unable to write new index file\");\ndiff --git a/t/t2014-switch.sh b/t/t2014-switch.sh\nnew file mode 100755\nindex 0000000..ccfb147\n--- /dev/null\n+++ b/t/t2014-switch.sh\n@@ -0,0 +1,28 @@\n+#!/bin/sh\n+\n+test_description='Peter MacMillan'\n+. ./test-lib.sh\n+\n+test_expect_success setup '\n+\techo Hello >file &&\n+\tgit add file &&\n+\ttest_tick &&\n+\tgit commit -m V1 &&\n+\techo Hello world >file &&\n+\tgit add file &&\n+\tgit checkout -b other\n+'\n+\n+test_expect_success 'check all changes are staged' '\n+\tgit diff --exit-code\n+'\n+\n+test_expect_success 'second commit' '\n+\tgit commit -m V2\n+'\n+\n+test_expect_success 'check' '\n+\tgit diff --cached --exit-code\n+'\n+\n+test_done\n-- \n1.6.3.9.g6345d\n"}]}