{"thread":{"id":"62758","subject":"git restore --staged -p on merge conflict causes crash","startedAt":"2025-01-07T14:58:29Z","lastAt":"2025-01-07T16:27:30Z","messageCount":3,"participants":["Keith Mendoza","Kristoffer Haugsbakk"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"510083","messageId":"DM8PR02MB7942969BE7FEAFB48D9AEDCEC7112@DM8PR02MB7942.namprd02.prod.outlook.com","threadId":"62758","inReplyTo":null,"subject":"git restore --staged -p on merge conflict causes crash","fromName":"Keith Mendoza","fromEmail":"kmendoza@beyondtrust.com","sentAt":"2025-01-07T14:41:39Z","receivedAt":"2025-01-07T14:58:29Z","isPatch":false,"sender":{"key":"kmendoza@beyondtrust.com","avatar":null},"body":"What did you do before the bug happened? (Steps to reproduce your issue)\n1. Start with a main branch\n1. Add a new file (test.yaml)\n1. git checkout --no-track -b branch-1\n1. Commit a change to test.yaml\n1. git checkout main\n1. Commit a change to the same lines in test.yaml that was updated in branch-1\n1. git checkout branch-1\n1. git merge main\n1. git restore --staged -p test.yaml\n\nWhat did you expect to happen? (Expected behavior)\nBe able to select which updates to restore\n\nWhat happened instead? (Actual behavior)\nThe following is displayed on the console\n```\nBUG: add-patch.c:497: diff starts with unexpected line:\n* Unmerged path test.yaml\n\nAborted (core dumped)\n```\n\nWhat's different between what you expected and what actually happened?\ngit crashed and generated a core dump.\n\nAnything else you want to add:\nHere's the output of git diff after the `git merge main`\n\n```\ndiff --cc test.yaml\nindex 26bf81a,46282a7..0000000\n--- a/test.yaml\n+++ b/test.yaml\n@@@ -1,7 -1,7 +1,13 @@@\n  job:\n++<<<<<<< HEAD\n +  newfield:\n +    field1: blah\n +    field2: blah-blah\n++=======\n+   conflict-field:\n+     blah1: blah-blah\n+     blah2: blah-blah-blah\n++>>>>>>> main\n    something:\n      required: true\n      other: 1\n```\n\nThe generated core dump is attached.\n\nPlease review the rest of the bug report below.\nYou can delete any lines you don't wish to share.\n\n\n[System Info]\ngit version:\ngit version 2.39.5\ncpu: x86_64\nno commit associated with this build\nsizeof-long: 8\nsizeof-size_t: 8\nshell-path: /bin/sh\nuname: Linux 5.15.167.4-microsoft-standard-WSL2 #1 SMP Tue Nov 5 00:21:55 UTC 2024 x86_64\ncompiler info: gnuc: 12.2\nlibc info: glibc: 2.36\n$SHELL (typically, interactive shell): /bin/bash\n\n\n[Enabled Hooks]\n"},{"id":"510087","messageId":"27ec479b-b116-4fa7-b87c-416a5f7f3b25@app.fastmail.com","threadId":"62758","inReplyTo":"DM8PR02MB7942969BE7FEAFB48D9AEDCEC7112@DM8PR02MB7942.namprd02.prod.outlook.com","subject":"Re: git restore --staged -p on merge conflict causes crash","fromName":"Kristoffer Haugsbakk","fromEmail":"kristofferhaugsbakk@fastmail.com","sentAt":"2025-01-07T15:34:19Z","receivedAt":"2025-01-07T15:34:53Z","isPatch":false,"sender":{"key":"kristofferhaugsbakk@fastmail.com","avatar":null},"body":"On Tue, Jan 7, 2025, at 15:41, Keith Mendoza wrote:\n> What did you do before the bug happened? (Steps to reproduce your issue)\n> 1. Start with a main branch\n> 1. Add a new file (test.yaml)\n> 1. git checkout --no-track -b branch-1\n> 1. Commit a change to test.yaml\n> 1. git checkout main\n> 1. Commit a change to the same lines in test.yaml that was updated in branch-1\n> 1. git checkout branch-1\n> 1. git merge main\n> 1. git restore --staged -p test.yaml\n>\n> What did you expect to happen? (Expected behavior)\n> Be able to select which updates to restore\n>\n> What happened instead? (Actual behavior)\n> The following is displayed on the console\n> ```\n> BUG: add-patch.c:497: diff starts with unexpected line:\n> * Unmerged path test.yaml\n>\n> Aborted (core dumped)\n> ```\n\nIt looks[1] like this was fixed in 28d1122f9ca (add-patch: handle \"*\nUnmerged path\" lines, 2023-03-09).[2] That fix was included in v2.41.0\nand later.  So not on your maintenance release (v2.39.5).\n\nThe bug was introduced in 2.37.0:\n\nJeff King wrote:\n> Thanks, a fix is below. While the escape-hatch of the perl version is\n> going away in v2.40, people have been exposed to the bug since we\n> flipped the default in v2.37.0.\n\nAt least I wasn’t able to reproduce on 2.48.0.rc2 with the below.\n\n```\ngit init &&\ntouch test.yaml &&\ngit add test.yaml &&\ngit commit -minit &&\ngit checkout --no-track -b branch-1 &&\necho something >test.yaml &&\ngit add test.yaml &&\ngit commit -mchange &&\ngit checkout main &&\necho 'something else (conflict)' >test.yaml &&\ngit add test.yaml &&\ngit commit -m'change here too' &&\ngit checkout branch-1 &&\n# Merge conflict\ngit merge main\ngit restore --staged -p test.yaml\n```\n\n† 1: Based on:\n\n      BUG: add-patch.c:498: diff starts with unexpected line:\n\n🔗 2: https://lore.kernel.org/git/ZAmfqC9WMl3XeyEr@coredump.intra.peff.net/\n"},{"id":"510092","messageId":"DM8PR02MB79428E0A2C6C32EA67D791D1C7112@DM8PR02MB7942.namprd02.prod.outlook.com","threadId":"62758","inReplyTo":"27ec479b-b116-4fa7-b87c-416a5f7f3b25@app.fastmail.com","subject":"RE: git restore --staged -p on merge conflict causes crash","fromName":"Keith Mendoza","fromEmail":"kmendoza@beyondtrust.com","sentAt":"2025-01-07T16:07:45Z","receivedAt":"2025-01-07T16:27:30Z","isPatch":false,"sender":{"key":"kmendoza@beyondtrust.com","avatar":null},"body":"Thanks for the information.\n\n\n-----Original Message-----\nFrom: Kristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com> \nSent: Tuesday, January 7, 2025 7:34 AM\nTo: Keith Mendoza <kmendoza@beyondtrust.com>; git@vger.kernel.org\nSubject: Re: git restore --staged -p on merge conflict causes crash\n\nThis email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.\n\n\nOn Tue, Jan 7, 2025, at 15:41, Keith Mendoza wrote:\n> What did you do before the bug happened? (Steps to reproduce your issue)\n> 1. Start with a main branch\n> 1. Add a new file (test.yaml)\n> 1. git checkout --no-track -b branch-1\n> 1. Commit a change to test.yaml\n> 1. git checkout main\n> 1. Commit a change to the same lines in test.yaml that was updated in branch-1\n> 1. git checkout branch-1\n> 1. git merge main\n> 1. git restore --staged -p test.yaml\n>\n> What did you expect to happen? (Expected behavior)\n> Be able to select which updates to restore\n>\n> What happened instead? (Actual behavior)\n> The following is displayed on the console\n> ```\n> BUG: add-patch.c:497: diff starts with unexpected line:\n> * Unmerged path test.yaml\n>\n> Aborted (core dumped)\n> ```\n\nIt looks[1] like this was fixed in 28d1122f9ca (add-patch: handle \"*\nUnmerged path\" lines, 2023-03-09).[2] That fix was included in v2.41.0\nand later.  So not on your maintenance release (v2.39.5).\n\nThe bug was introduced in 2.37.0:\n\nJeff King wrote:\n> Thanks, a fix is below. While the escape-hatch of the perl version is\n> going away in v2.40, people have been exposed to the bug since we\n> flipped the default in v2.37.0.\n\nAt least I wasn’t able to reproduce on 2.48.0.rc2 with the below.\n\n```\ngit init &&\ntouch test.yaml &&\ngit add test.yaml &&\ngit commit -minit &&\ngit checkout --no-track -b branch-1 &&\necho something >test.yaml &&\ngit add test.yaml &&\ngit commit -mchange &&\ngit checkout main &&\necho 'something else (conflict)' >test.yaml &&\ngit add test.yaml &&\ngit commit -m'change here too' &&\ngit checkout branch-1 &&\n# Merge conflict\ngit merge main\ngit restore --staged -p test.yaml\n```\n\n† 1: Based on:\n\n      BUG: add-patch.c:498: diff starts with unexpected line:\n\n🔗 2: https://urldefense.com/v3/__https://lore.kernel.org/git/ZAmfqC9WMl3XeyEr@coredump.intra.peff.net/__;!!GAuxx38R6fLb!Jh_X9EDKuOi07wcMoWg66W79Lx_4t8FDTQeu-coao1J1o1a51DUz8ce6MOvCVMIUHqsP1IaqVB02dIITAty5bP4W5X6vVR0m$\n"}]}