* Pressing Ctrl-C during 'git checkout <branch-name>' messes up the repository
@ 2023-07-15 4:26 Yuri
2023-07-16 0:24 ` brian m. carlson
0 siblings, 1 reply; 6+ messages in thread
From: Yuri @ 2023-07-15 4:26 UTC (permalink / raw)
To: Git Mailing List
It stops in some intermediate state, and git still says that it is on
the main branch, but 'git checkout' deletes files that were added only
in the main branch,
'git reset --hard HEAD' fixes the main branch, bit now it is impossible
to switch to the other branch because it says that "some files would be
overwritten", which shouldn't be the case.
All operations should be atomic.
When the user presses Ctrl-C, the correct action would be to cleanly
return to the initial branch.
git-2.41.0
Thanks,
Yuri
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Pressing Ctrl-C during 'git checkout <branch-name>' messes up the repository
2023-07-15 4:26 Pressing Ctrl-C during 'git checkout <branch-name>' messes up the repository Yuri
@ 2023-07-16 0:24 ` brian m. carlson
2023-07-16 1:15 ` Junio C Hamano
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: brian m. carlson @ 2023-07-16 0:24 UTC (permalink / raw)
To: Yuri; +Cc: Git Mailing List
[-- Attachment #1: Type: text/plain, Size: 1444 bytes --]
On 2023-07-15 at 04:26:46, Yuri wrote:
> It stops in some intermediate state, and git still says that it is on the
> main branch, but 'git checkout' deletes files that were added only in the
> main branch,
>
> 'git reset --hard HEAD' fixes the main branch, bit now it is impossible to
> switch to the other branch because it says that "some files would be
> overwritten", which shouldn't be the case.
>
>
> All operations should be atomic.
This is impossible, since POSIX doesn't provide the functionality for us
to perform operations atomically. There are various reasons, including
permissions and files differing in case on a case-insensitive system,
why an operation might not succeed part way through.
> When the user presses Ctrl-C, the correct action would be to cleanly return
> to the initial branch.
I would disagree here. When the user has hit Ctrl-C, they want to
interrupt the operation. That's literally why a SIGINT (interrupt)
signal is sent. A checkout can take a long time, and the user will not
want Git to perform an operation which will take even longer than the
original one (because the original checkout was aborted).
Even if we did that, the user could just hit Ctrl-C again and really
interrupt the process, and then they'd be stuck again.
If you don't want to interrupt the operation, then don't hit Ctrl-C.
--
brian m. carlson (he/him or they/them)
Toronto, Ontario, CA
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 263 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Pressing Ctrl-C during 'git checkout <branch-name>' messes up the repository
2023-07-16 0:24 ` brian m. carlson
@ 2023-07-16 1:15 ` Junio C Hamano
2023-07-17 0:16 ` Yuri
2023-07-17 9:18 ` Konstantin Khomoutov
2 siblings, 0 replies; 6+ messages in thread
From: Junio C Hamano @ 2023-07-16 1:15 UTC (permalink / raw)
To: brian m. carlson; +Cc: Yuri, Git Mailing List
"brian m. carlson" <sandals@crustytoothpaste.net> writes:
>> When the user presses Ctrl-C, the correct action would be to cleanly return
>> to the initial branch.
>
> I would disagree here. When the user has hit Ctrl-C, they want to
> interrupt the operation. That's literally why a SIGINT (interrupt)
> signal is sent. A checkout can take a long time, and the user will not
> want Git to perform an operation which will take even longer than the
> original one (because the original checkout was aborted).
>
> Even if we did that, the user could just hit Ctrl-C again and really
> interrupt the process, and then they'd be stuck again.
>
> If you don't want to interrupt the operation, then don't hit Ctrl-C.
I agree with all of the above, but stopping with "don't" is not very
helpful---people do do things that they are told not to anyway, and
it makes a whole lot of difference if they know how to recover from
the fallout of their actions. It would help to teach "reset --hard"
or something that lets the user to return to a known state. It may
not necessarily be the state the user would want to go, but it is
still better to be in a known stable state and be able to complain
"I lost my stashed changes" or "I lost a few commits" than to be in
a state where the user is totally lost and do not know what to do
next.
Of course, that kind of coaching is not something we should do in
our error or advise messages, but in an early part of the tutorial
or somewhere, perhaps?
Thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Pressing Ctrl-C during 'git checkout <branch-name>' messes up the repository
2023-07-16 0:24 ` brian m. carlson
2023-07-16 1:15 ` Junio C Hamano
@ 2023-07-17 0:16 ` Yuri
2023-07-17 9:18 ` Konstantin Khomoutov
2 siblings, 0 replies; 6+ messages in thread
From: Yuri @ 2023-07-17 0:16 UTC (permalink / raw)
To: brian m. carlson, Git Mailing List
On 7/15/23 17:24, brian m. carlson wrote:
> If you don't want to interrupt the operation, then don't hit Ctrl-C.
A more comprehensive way to handle this is to offer the user a choice:
Ctrl-C was pressed during a long operation. Please choose:
(1) press Ctrl-C again to stop immediately while likely leaving the
repository in inconsistent state
(2) press C to continue
(3) press R to roll back the current operation
And if the user would press Ctrl-C again during the rollback - he would
be presented with choices:
Ctrl-C was pressed during the roll back of a long operation. Please choose:
(1) press Ctrl-C again to stop immediately while likely leaving the
repository in inconsistent state
(2) press C to continue the rollback
This would be a lot better than to just stop immediately and leave the
repository damaged.
Yuri
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Pressing Ctrl-C during 'git checkout <branch-name>' messes up the repository
2023-07-16 0:24 ` brian m. carlson
2023-07-16 1:15 ` Junio C Hamano
2023-07-17 0:16 ` Yuri
@ 2023-07-17 9:18 ` Konstantin Khomoutov
2023-07-17 16:35 ` Andreas Schwab
2 siblings, 1 reply; 6+ messages in thread
From: Konstantin Khomoutov @ 2023-07-17 9:18 UTC (permalink / raw)
To: Git Mailing List
"brian m. carlson" <sandals@crustytoothpaste.net> writes:
> I would disagree here. When the user has hit Ctrl-C, they want to
> interrupt the operation. That's literally why a SIGINT (interrupt)
> signal is sent.
Just a fun remark: that "INT" in SIGINT stands for "INTeractive attention",
and IIUC, relabeling it as a request for interruption in the public
consciousness is likely the result of that signal having been left in its
default disposition in most of the software which was in use then, which
naturally made the signal work as a termination signal ;-)
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Pressing Ctrl-C during 'git checkout <branch-name>' messes up the repository
2023-07-17 9:18 ` Konstantin Khomoutov
@ 2023-07-17 16:35 ` Andreas Schwab
0 siblings, 0 replies; 6+ messages in thread
From: Andreas Schwab @ 2023-07-17 16:35 UTC (permalink / raw)
To: Git Mailing List
On Jul 17 2023, Konstantin Khomoutov wrote:
> Just a fun remark: that "INT" in SIGINT stands for "INTeractive attention",
Do you have a source for that? The oldest manpage for signal(2)
available at man.freebsd.org describes it as "interrupt".
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-07-17 16:35 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-15 4:26 Pressing Ctrl-C during 'git checkout <branch-name>' messes up the repository Yuri
2023-07-16 0:24 ` brian m. carlson
2023-07-16 1:15 ` Junio C Hamano
2023-07-17 0:16 ` Yuri
2023-07-17 9:18 ` Konstantin Khomoutov
2023-07-17 16:35 ` Andreas Schwab
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).