{"thread":{"id":"42518","subject":"--orphan erases HEAD reflog","startedAt":"2016-06-03T11:28:13Z","lastAt":"2016-06-04T01:54:27Z","messageCount":4,"participants":["Patrik Gustafsson","SZEDER Gábor","Eric Sunshine"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"288223","messageId":"f51f9df7-d6d7-3a45-736f-ca2e2c9eb2cb@textalk.se","threadId":"42518","inReplyTo":null,"subject":"--orphan erases HEAD reflog","fromName":"Patrik Gustafsson","fromEmail":"pvn@textalk.se","sentAt":"2016-06-03T11:28:13Z","receivedAt":"2016-06-03T11:28:13Z","isPatch":false,"sender":{"key":"pvn@textalk.se","avatar":null},"body":"after running the command:\n\ngit checkout --orphan fuleFix\n\nmy HEAD reflog is emptied.\nI would like to have my reflog intact :)\n\ngit version 2.8.3\n\ndist:\nManjaro\n\nthanx for being awesome\n"},{"id":"288290","messageId":"20160603203818.7654-1-szeder@ira.uka.de","threadId":"42518","inReplyTo":"f51f9df7-d6d7-3a45-736f-ca2e2c9eb2cb@textalk.se","subject":"Re: --orphan erases HEAD reflog","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2016-06-03T20:38:18Z","receivedAt":"2016-06-03T20:38:18Z","isPatch":false,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"> after running the command:\n> \n> git checkout --orphan fuleFix\n> \n> my HEAD reflog is emptied.\n> I would like to have my reflog intact :)\n\nNo worries, your reflog is still intact :)  It's just the reflog\nwalker stopping prematurely upon encountering the null sha1 of the new\nroot commit's reflog entry.  Patch follows in a minute.\n\nOf course you still won't be able to list the reflog right after 'git\ncheckout --orphan', because HEAD is invalid.  You have to create a new\nroot commit or switch to an existing branch first.\n\n\nGábor\n"},{"id":"288292","messageId":"20160603204235.7994-1-szeder@ira.uka.de","threadId":"42518","inReplyTo":"f51f9df7-d6d7-3a45-736f-ca2e2c9eb2cb@textalk.se","subject":"[PATCH] reflog: continue walking the reflog past root commits","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2016-06-03T20:42:35Z","receivedAt":"2016-06-03T20:42:35Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"If a repository contains more than one root commit, then its HEAD\nreflog may contain multiple \"creation events\", i.e. entries whose\n\"from\" value is the null sha1.  Listing such a reflog currently stops\nprematurely at the first such entry, even when the reflog still\ncontains older entries.  This can scare users into thinking that their\nreflog got truncated after 'git checkout --orphan'.\n\nContinue walking the reflog past such creation evens based on the\npreceeding reflog entry's \"new\" value.\n\nThe test 'symbolic-ref writes reflog entry' in t1401-symbolic-ref\nimplicitly relies on the current behavior of the reflog walker to stop\nat a root commit and thus to list only the reflog entries that are\nrelevant for that test.  Adjust the test to explicitly specify the\nnumber of relevant reflog entries to be listed.\n\nReported-by: Patrik Gustafsson <pvn@textalk.se>\nSigned-off-by: SZEDER Gábor <szeder@ira.uka.de>\n---\n reflog-walk.c           |  6 ++++++\n t/t1401-symbolic-ref.sh |  2 +-\n t/t1410-reflog.sh       | 22 ++++++++++++++++++++++\n 3 files changed, 29 insertions(+), 1 deletion(-)\n\ndiff --git a/reflog-walk.c b/reflog-walk.c\nindex 0ebd1da5ceb8..a246af27678a 100644\n--- a/reflog-walk.c\n+++ b/reflog-walk.c\n@@ -241,6 +241,12 @@ void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit)\n \t\tlogobj = parse_object(reflog->osha1);\n \t} while (commit_reflog->recno && (logobj && logobj->type != OBJ_COMMIT));\n \n+\tif (!logobj && commit_reflog->recno >= 0 && is_null_sha1(reflog->osha1)) {\n+\t\t/* a root commit, but there are still more entries to show */\n+\t\treflog = &commit_reflog->reflogs->items[commit_reflog->recno];\n+\t\tlogobj = parse_object(reflog->nsha1);\n+\t}\n+\n \tif (!logobj || logobj->type != OBJ_COMMIT) {\n \t\tcommit_info->commit = NULL;\n \t\tcommit->parents = NULL;\ndiff --git a/t/t1401-symbolic-ref.sh b/t/t1401-symbolic-ref.sh\nindex 417eecc3af2a..ca3fa406c34f 100755\n--- a/t/t1401-symbolic-ref.sh\n+++ b/t/t1401-symbolic-ref.sh\n@@ -110,7 +110,7 @@ test_expect_success 'symbolic-ref writes reflog entry' '\n \tupdate\n \tcreate\n \tEOF\n-\tgit log --format=%gs -g >actual &&\n+\tgit log --format=%gs -g -2 >actual &&\n \ttest_cmp expect actual\n '\n \ndiff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh\nindex 9cf91dc6d217..dd2be049ecf6 100755\n--- a/t/t1410-reflog.sh\n+++ b/t/t1410-reflog.sh\n@@ -348,4 +348,26 @@ test_expect_success 'reflog expire operates on symref not referrent' '\n \tgit reflog expire --expire=all the_symref\n '\n \n+test_expect_success 'continue walking past root commits' '\n+\tgit init orphanage &&\n+\t(\n+\t\tcd orphanage &&\n+\t\tcat >expect <<-\\EOF &&\n+\t\tHEAD@{0} commit (initial): orphan2-1\n+\t\tHEAD@{1} commit: orphan1-2\n+\t\tHEAD@{2} commit (initial): orphan1-1\n+\t\tHEAD@{3} commit (initial): initial\n+\t\tEOF\n+\t\ttest_commit initial &&\n+\t\tgit reflog &&\n+\t\tgit checkout --orphan orphan1 &&\n+\t\ttest_commit orphan1-1 &&\n+\t\ttest_commit orphan1-2 &&\n+\t\tgit checkout --orphan orphan2 &&\n+\t\ttest_commit orphan2-1 &&\n+\t\tgit log -g --format=\"%gd %gs\" >actual &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n test_done\n-- \n2.9.0.rc1.66.ge2c3978\n"},{"id":"288358","messageId":"CAPig+cRwvfQ3hL9XKHteGr30M4eMKZm19_UCXGxuoqsxvXje4A@mail.gmail.com","threadId":"42518","inReplyTo":"20160603204235.7994-1-szeder@ira.uka.de","subject":"Re: [PATCH] reflog: continue walking the reflog past root commits","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2016-06-04T01:54:27Z","receivedAt":"2016-06-04T01:54:27Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Fri, Jun 3, 2016 at 4:42 PM, SZEDER Gábor <szeder@ira.uka.de> wrote:\n> If a repository contains more than one root commit, then its HEAD\n> reflog may contain multiple \"creation events\", i.e. entries whose\n> \"from\" value is the null sha1.  Listing such a reflog currently stops\n> prematurely at the first such entry, even when the reflog still\n> contains older entries.  This can scare users into thinking that their\n> reflog got truncated after 'git checkout --orphan'.\n>\n> Continue walking the reflog past such creation evens based on the\n\ns/evens/events/\n\n> preceeding reflog entry's \"new\" value.\n>\n> The test 'symbolic-ref writes reflog entry' in t1401-symbolic-ref\n> implicitly relies on the current behavior of the reflog walker to stop\n> at a root commit and thus to list only the reflog entries that are\n> relevant for that test.  Adjust the test to explicitly specify the\n> number of relevant reflog entries to be listed.\n>\n> Reported-by: Patrik Gustafsson <pvn@textalk.se>\n> Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>\n"}]}