{"thread":{"id":"59989","subject":"Pressing Ctrl-C during 'git checkout <branch-name>' messes up the repository","startedAt":"2023-07-15T04:37:09Z","lastAt":"2023-07-17T16:35:19Z","messageCount":6,"participants":["Yuri","brian m. carlson","Junio C Hamano","Konstantin Khomoutov","Andreas Schwab"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"479542","messageId":"fe3c68d5-124e-5a87-881a-21ad8e492f76@tsoft.com","threadId":"59989","inReplyTo":null,"subject":"Pressing Ctrl-C during 'git checkout <branch-name>' messes up the repository","fromName":"Yuri","fromEmail":"yuri@rawbw.com","sentAt":"2023-07-15T04:26:46Z","receivedAt":"2023-07-15T04:37:09Z","isPatch":false,"sender":{"key":"yuri@rawbw.com","avatar":null},"body":"It stops in some intermediate state, and git still says that it is on \nthe main branch, but 'git checkout' deletes files that were added only \nin the main branch,\n\n'git reset --hard HEAD' fixes the main branch, bit now it is impossible \nto switch to the other branch because it says that \"some files would be \noverwritten\", which shouldn't be the case.\n\n\nAll operations should be atomic.\n\nWhen the user presses Ctrl-C, the correct action would be to cleanly \nreturn to the initial branch.\n\n\ngit-2.41.0\n\n\nThanks,\n\nYuri\n\n\n"},{"id":"479551","messageId":"ZLM4sTUjBQt4QMfG@tapette.crustytoothpaste.net","threadId":"59989","inReplyTo":"fe3c68d5-124e-5a87-881a-21ad8e492f76@tsoft.com","subject":"Re: Pressing Ctrl-C during 'git checkout <branch-name>' messes up the repository","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2023-07-16T00:24:17Z","receivedAt":"2023-07-16T00:24:24Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2023-07-15 at 04:26:46, Yuri wrote:\n> It stops in some intermediate state, and git still says that it is on the\n> main branch, but 'git checkout' deletes files that were added only in the\n> main branch,\n> \n> 'git reset --hard HEAD' fixes the main branch, bit now it is impossible to\n> switch to the other branch because it says that \"some files would be\n> overwritten\", which shouldn't be the case.\n> \n> \n> All operations should be atomic.\n\nThis is impossible, since POSIX doesn't provide the functionality for us\nto perform operations atomically.  There are various reasons, including\npermissions and files differing in case on a case-insensitive system,\nwhy an operation might not succeed part way through.\n\n> When the user presses Ctrl-C, the correct action would be to cleanly return\n> to the initial branch.\n\nI would disagree here.  When the user has hit Ctrl-C, they want to\ninterrupt the operation.  That's literally why a SIGINT (interrupt)\nsignal is sent.  A checkout can take a long time, and the user will not\nwant Git to perform an operation which will take even longer than the\noriginal one (because the original checkout was aborted).\n\nEven if we did that, the user could just hit Ctrl-C again and really\ninterrupt the process, and then they'd be stuck again.\n\nIf you don't want to interrupt the operation, then don't hit Ctrl-C.\n-- \nbrian m. carlson (he/him or they/them)\nToronto, Ontario, CA\n"},{"id":"479553","messageId":"xmqqedl8lkqu.fsf@gitster.g","threadId":"59989","inReplyTo":"ZLM4sTUjBQt4QMfG@tapette.crustytoothpaste.net","subject":"Re: Pressing Ctrl-C during 'git checkout <branch-name>' messes up the repository","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-07-16T01:15:37Z","receivedAt":"2023-07-16T01:15:45Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n\n>> When the user presses Ctrl-C, the correct action would be to cleanly return\n>> to the initial branch.\n>\n> I would disagree here.  When the user has hit Ctrl-C, they want to\n> interrupt the operation.  That's literally why a SIGINT (interrupt)\n> signal is sent.  A checkout can take a long time, and the user will not\n> want Git to perform an operation which will take even longer than the\n> original one (because the original checkout was aborted).\n>\n> Even if we did that, the user could just hit Ctrl-C again and really\n> interrupt the process, and then they'd be stuck again.\n>\n> If you don't want to interrupt the operation, then don't hit Ctrl-C.\n\nI agree with all of the above, but stopping with \"don't\" is not very\nhelpful---people do do things that they are told not to anyway, and\nit makes a whole lot of difference if they know how to recover from\nthe fallout of their actions.  It would help to teach \"reset --hard\"\nor something that lets the user to return to a known state.  It may\nnot necessarily be the state the user would want to go, but it is\nstill better to be in a known stable state and be able to complain\n\"I lost my stashed changes\" or \"I lost a few commits\" than to be in\na state where the user is totally lost and do not know what to do\nnext.\n\nOf course, that kind of coaching is not something we should do in\nour error or advise messages, but in an early part of the tutorial\nor somewhere, perhaps?\n\nThanks.\n"},{"id":"479563","messageId":"9e5b5818-6107-134f-b4ce-3a6028417838@tsoft.com","threadId":"59989","inReplyTo":"ZLM4sTUjBQt4QMfG@tapette.crustytoothpaste.net","subject":"Re: Pressing Ctrl-C during 'git checkout <branch-name>' messes up the repository","fromName":"Yuri","fromEmail":"yuri@rawbw.com","sentAt":"2023-07-17T00:16:21Z","receivedAt":"2023-07-17T00:16:30Z","isPatch":false,"sender":{"key":"yuri@rawbw.com","avatar":null},"body":"On 7/15/23 17:24, brian m. carlson wrote:\n> If you don't want to interrupt the operation, then don't hit Ctrl-C.\n\n\nA more comprehensive way to handle this is to offer the user a choice:\n\nCtrl-C was pressed during a long operation. Please choose:\n\n(1) press Ctrl-C again to stop immediately while likely leaving the \nrepository in inconsistent state\n\n(2) press C to continue\n\n(3) press R to roll back the current operation\n\n\nAnd if the user would press Ctrl-C again during the rollback - he would \nbe presented with choices:\n\nCtrl-C was pressed during the roll back of a long operation. Please choose:\n\n(1) press Ctrl-C again to stop immediately while likely leaving the \nrepository in inconsistent state\n\n(2) press C to continue the rollback\n\n\nThis would be a lot better than to just stop immediately and leave the \nrepository damaged.\n\n\n\nYuri\n\n\n\n\n"},{"id":"479571","messageId":"20230717091849.z7bvqbygbpg4sluk@carbon","threadId":"59989","inReplyTo":"ZLM4sTUjBQt4QMfG@tapette.crustytoothpaste.net","subject":"Re: Pressing Ctrl-C during 'git checkout <branch-name>' messes up the repository","fromName":"Konstantin Khomoutov","fromEmail":"kostix@bswap.ru","sentAt":"2023-07-17T09:18:49Z","receivedAt":"2023-07-17T10:45:03Z","isPatch":false,"sender":{"key":"kostix@bswap.ru","avatar":null},"body":"\"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n\n> I would disagree here.  When the user has hit Ctrl-C, they want to\n> interrupt the operation.  That's literally why a SIGINT (interrupt)\n> signal is sent.\n\nJust a fun remark: that \"INT\" in SIGINT stands for \"INTeractive attention\",\nand IIUC, relabeling it as a request for interruption in the public\nconsciousness is likely the result of that signal having been left in its\ndefault disposition in most of the software which was in use then, which\nnaturally made the signal work as a termination signal ;-)\n\n"},{"id":"479578","messageId":"87bkgalcn8.fsf@igel.home","threadId":"59989","inReplyTo":"20230717091849.z7bvqbygbpg4sluk@carbon","subject":"Re: Pressing Ctrl-C during 'git checkout <branch-name>' messes up the repository","fromName":"Andreas Schwab","fromEmail":"schwab@linux-m68k.org","sentAt":"2023-07-17T16:35:07Z","receivedAt":"2023-07-17T16:35:19Z","isPatch":false,"sender":{"key":"schwab@linux-m68k.org","avatar":"https://avatars.githubusercontent.com/u/2175493?v=4"},"body":"On Jul 17 2023, Konstantin Khomoutov wrote:\n\n> Just a fun remark: that \"INT\" in SIGINT stands for \"INTeractive attention\",\n\nDo you have a source for that?  The oldest manpage for signal(2)\navailable at man.freebsd.org describes it as \"interrupt\".\n\n-- \nAndreas Schwab, schwab@linux-m68k.org\nGPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1\n\"And now for something completely different.\"\n"}]}