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

Adding any file to gitignore prompts to reload any notebook with unsaved changes #758

Closed
ianhi opened this issue Aug 31, 2020 · 0 comments · Fixed by #759
Closed

Adding any file to gitignore prompts to reload any notebook with unsaved changes #758

ianhi opened this issue Aug 31, 2020 · 0 comments · Fixed by #759

Comments

@ianhi
Copy link
Collaborator

ianhi commented Aug 31, 2020

Description

If you add a file to the gitignore while you have any files open that have unsaved changes then the UI will prompt you to reload those files. This will throw away unsaved changes to files that were not involved in the git action.

gitignore-unsaved-changes

I think the jupyterlab warning is a bit unclear here as to which notebook is going to be reloaded. Which then makes this a dangerously easy way for someone to lose unsaved work.

This is caused by these lines:

await gitModel.commands.execute('docmanager:reload');
await gitModel.commands.execute('docmanager:open', {
path: model.getRelativeFilePath('.gitignore')
});

Which I think are run to ensure that an updated .gitignore file is displayed. @echarles is this the correct reason for the docmanager:reload?

I think we can get the same effect without the reload by reverting the file similar to here:

jupyterlab-git/src/model.ts

Lines 1432 to 1437 in 7f3e4cc

private _revertFile(path: string): void {
const widget = this._docmanager.findWidget(this.getRelativeFilePath(path));
if (widget && !widget.context.model.dirty) {
widget.context.revert();
}
}

Reproduce

  1. Have an open notebook with unsaved changes
  2. add any file to gitignore
  3. see prompt asking you to reload notebook
  4. if you click reload all unsaved changes will be lost

Expected behavior

Context

  • Python package version: 0.21.0
  • Extension version: 0.21.0
  • Git version: 2.25.1
  • Operating System and its version: PopOS 20.04
Command Line Output
Paste the output from your command line running `jupyter lab` here, use `--debug` if possible.
Browser Output
Paste the output from your browser Javascript console here.
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 a pull request may close this issue.

1 participant