-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Help the user fix their working copy if it gets into a bad state #751
Conversation
f0c4ac3
to
0b1ede6
Compare
If Kart crashes or otherwise is aborted partway through a checkout operation, it is possible for the contents of the working copy or individual working copy parts to end up out of sync with what should be checked out based on the git file `.kart/HEAD`. Until now, this caused an internal error to be raised - WorkingCopyTreeMismatch, which gave some clues as to what had gone wrong but no real help on how to fix it. Since Kart checks the WC state is valid as a precondition to most commands, arriving in this state with no clear idea of how to get out of it makes a Kart repo feel pretty broken, as most commands will simply raise the same internal error. This change adds an external error including error code (which also suppresses the stack trace). The error message contains instructions on how to fix the repo so that it can be used again, and if run in an interactive terminal, prompts the user to decide if they want to try this remedy immediately.
0b1ede6
to
718474d
Compare
kart/working_copy.py
Outdated
subctx = click.Context(ctx.command, parent=ctx) | ||
subctx.obj = ctx.obj | ||
subctx.invoke(create_workingcopy, delete_existing=True, discard_changes=True) | ||
sys.exit(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you get here by running another command, seems like we should not exit here and instead just run the original command
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a prompt to see if the user still wants to do it. Didn't want to do it by default since it may not still make sense (ie, probably the command depends on the state of the WC in some way or we wouldn't have got here).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you give an example of what they might be trying to do that would now be a bad thing to do?
status/diff/commit would all be sensible here AFAICT (commit would just noop due to no changes)
If Kart crashes or otherwise is aborted partway through a checkout operation, it is possible for the contents of the working copy or individual working copy parts to end up out of sync with what should be checked out based on the git file
.kart/HEAD
.Until now, this caused an internal error to be raised - WorkingCopyTreeMismatch, which gave some clues as to what had gone wrong but no real help on how to fix it. Since Kart checks the WC state is valid as a precondition to many commands, arriving in this state with no clear idea of how to get out of it makes a Kart repo feel pretty broken, as most commands will simply raise the same internal error.
This change adds an external error including error code (which also suppresses the stack trace). The error message
contains instructions on how to fix the repo so that it can be used again, and if run in an interactive terminal, prompts
the user to decide if they want to try this remedy immediately.