{"thread":{"id":"61240","subject":":/regex syntax picks stash entries over regular commits","startedAt":"2024-03-31T22:13:15Z","lastAt":"2024-04-01T02:44:13Z","messageCount":3,"participants":["Nude F. Ninja","Junio C Hamano","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"491930","messageId":"CAOSCdbFg8jY1_0JE0+xf8oxrJjx-Kj0Cb0pPg3oUAXMN5q=kzw@mail.gmail.com","threadId":"61240","inReplyTo":null,"subject":":/regex syntax picks stash entries over regular commits","fromName":"Nude F. Ninja","fromEmail":"nudefninja@gmail.com","sentAt":"2024-03-31T22:13:03Z","receivedAt":"2024-03-31T22:13:15Z","isPatch":false,"sender":{"key":"nudefninja@gmail.com","avatar":null},"body":"What did you do before the bug happened? (Steps to reproduce your issue)\nI ran git stash push, which created the stash entry \"On main: dark\nmode\". Then I committed changes before noticing an oversight with the\nprevious commit. I wrote the fix and ran git commit --fixup :/dark\n\nWhat did you expect to happen? (Expected behavior)\nThe fixup commit should have referenced the previous commit.\n\nWhat happened instead? (Actual behavior)\nIt referenced the stash entry.\n\nWhat's different between what you expected and what actually happened?\nI cannot autosquash the commit that refers to the stash entry. I\nsuggest adding an option to prefer (older) regular commits over\n(newer) stash entries when specifying a commit with the :/regex\nsyntax. In any case I think it's a bug for the --fixup option to\nreadily produce a commit that does not work with the --autosquash\noption which it seems it was designed for.\n\n\n[System Info]\ngit version:\ngit version 2.39.3 (Apple Git-146)\n"},{"id":"491935","messageId":"xmqqy19ydmro.fsf@gitster.g","threadId":"61240","inReplyTo":"CAOSCdbFg8jY1_0JE0+xf8oxrJjx-Kj0Cb0pPg3oUAXMN5q=kzw@mail.gmail.com","subject":"Re: :/regex syntax picks stash entries over regular commits","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-03-31T23:06:35Z","receivedAt":"2024-03-31T23:06:41Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Nude F. Ninja\" <nudefninja@gmail.com> writes:\n\n> What did you do before the bug happened? (Steps to reproduce your issue)\n> I ran git stash push, which created the stash entry \"On main: dark\n> mode\". Then I committed changes before noticing an oversight with the\n> previous commit. I wrote the fix and ran git commit --fixup :/dark\n\nIt is natural that there are multiple commits that match the pattern\nyou give in your repository.\n\nOne trick I learned that is effective is to explicitly state where\nto start searches, e.g. \"--fixup 'HEAD^{/dark mode}'\", which would\nbe very much in line to what --fixup wants to do.  The commit to be\nfixed up in a later rebase session by definition must be an ancestor\nof the current HEAD.\n"},{"id":"491939","messageId":"20240401024411.GA2639525@coredump.intra.peff.net","threadId":"61240","inReplyTo":"xmqqy19ydmro.fsf@gitster.g","subject":"Re: :/regex syntax picks stash entries over regular commits","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2024-04-01T02:44:11Z","receivedAt":"2024-04-01T02:44:13Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Mar 31, 2024 at 04:06:35PM -0700, Junio C Hamano wrote:\n\n> \"Nude F. Ninja\" <nudefninja@gmail.com> writes:\n> \n> > What did you do before the bug happened? (Steps to reproduce your issue)\n> > I ran git stash push, which created the stash entry \"On main: dark\n> > mode\". Then I committed changes before noticing an oversight with the\n> > previous commit. I wrote the fix and ran git commit --fixup :/dark\n> \n> It is natural that there are multiple commits that match the pattern\n> you give in your repository.\n> \n> One trick I learned that is effective is to explicitly state where\n> to start searches, e.g. \"--fixup 'HEAD^{/dark mode}'\", which would\n> be very much in line to what --fixup wants to do.  The commit to be\n> fixed up in a later rebase session by definition must be an ancestor\n> of the current HEAD.\n\nYeah, the \"traverse all commits\" aspect of \":/\" is well known and\nconfusing, and why we introduced the rev ^{/} syntax. But I still wonder\nif it would be better to limit \":/\" to something more sensible. Finding\n\"refs/stash\" or \"refs/notes/*\" is downright confusing (stash especially\nbecause we don't walk the reflog, so it sees only stash@{0}, and not the\nothers!).\n\nIt would be pretty easy to do the equivalent of \"--branches --tags\n--remotes\":\n\ndiff --git a/object-name.c b/object-name.c\nindex 523af6f64f..5285903f78 100644\n--- a/object-name.c\n+++ b/object-name.c\n@@ -2002,7 +2002,9 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n \n \t\t\tcb.repo = repo;\n \t\t\tcb.list = &list;\n-\t\t\trefs_for_each_ref(get_main_ref_store(repo), handle_one_ref, &cb);\n+\t\t\trefs_for_each_ref_in(get_main_ref_store(repo), \"refs/heads/\", handle_one_ref, &cb);\n+\t\t\trefs_for_each_ref_in(get_main_ref_store(repo), \"refs/tags/\", handle_one_ref, &cb);\n+\t\t\trefs_for_each_ref_in(get_main_ref_store(repo), \"refs/remotes/\", handle_one_ref, &cb);\n \t\t\trefs_head_ref(get_main_ref_store(repo), handle_one_ref, &cb);\n \t\t\tcommit_list_sort_by_date(&list);\n \t\t\treturn get_oid_oneline(repo, name + 2, oid, list);\n\nOr alternatively to skip known-confusing parts of the namespace like\nrefs/stash.\n\nI dunno. I have long ago written off :/ as useless, so maybe trying to\nmake it slightly less confusing is a fool's errand. Maybe we'd be better\noff putting a note in its documentation that rev^{/} is more likely to\ndo what you want.\n\n-Peff\n"}]}