Skip to content
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

Merged
merged 3 commits into from
Dec 21, 2022

Conversation

olsen232
Copy link
Collaborator

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.

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.
kart/working_copy.py Outdated Show resolved Hide resolved
kart/working_copy.py Outdated Show resolved Hide resolved
kart/working_copy.py Outdated Show resolved Hide resolved
subctx = click.Context(ctx.command, parent=ctx)
subctx.obj = ctx.obj
subctx.invoke(create_workingcopy, delete_existing=True, discard_changes=True)
sys.exit(0)
Copy link
Member

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

Copy link
Collaborator Author

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).

Copy link
Member

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants