-
Notifications
You must be signed in to change notification settings - Fork 326
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
Update open files when Git commands modify them #676
Conversation
I'm working on a rebase of this post #630 and have a quick question for either @fcollonval or @kgryte. Should the code that reverts the file should be inside the modal's try block? It seems to me the answer is yes, however if I do that then I will need to put the check on try {
const files = (await this.changedFiles(null, null, commitId))['files'];
const response = await httpGitRequest('/git/delete_commit', 'POST', {
commit_id: commitId,
top_repo_path: path
});
if (!response.ok) {
return response.json().then((data: any) => {
throw new ServerConnection.ResponseError(response, data.message);
});
}
if (files) {
files.forEach(file => {
this._revertFile(file);
});
}
await this.commit(message);
return response;
} catch (err) {
throw new ServerConnection.NetworkError(err);
} finally {
this._removeTask(tid);
} vs this: Lines 624 to 640 in 4c3dbe2
|
@ian-r-rose I recommend only wrapping what is absolutely necessary in a In the above, including substantial code blocks (i.e., many lines of code) increases the risk of trapping unintentional errors, such as syntax errors, etc, in which the application continues to run as normal due to the trapping or even responds with an erroneous error message making debugging more difficult. |
@kgryte thanks for the help.
Do you mean that reverting the files should be outside the try block? That seems problematic because reverting files should (I think) be hidden behind the modal to prevent further user modifications while files are being modified. Alternatively I could move the revertFiles call outside of the try..finally and give it it's own modal, but then there would end up being two modal's spawned which does not seem ideal. |
Ah, right. You could just move the |
Ah ok that sounds reasonable. I was worried that it was important to have |
Nope. :) Just "bracket" the operations in which the modal should be present. For many of the operations for which I added the modal, there was only one operation for which we needed to show the modal. Hence, our ability to use |
A small note about future change. I plan to push a proposal to handle connection and response error directly within Related to that @kgryte, would it make sense to create executeTask(name, fn, ...args) {
this._addTask(name);
try{
fn(...args)
} finally {
this._removeTask(name)
}
} That will simplify the code and improve its robustness. But in light of the problem expose here. It could be better to have: executeTask(name, fnAndArgs[]: Array<{fn, args[]}>) {
this._addTask(name);
try{
fnAndArgs.forEach({fn, args} => { fn(..args) });
} finally {
this._removeTask(name)
}
} |
Personally, I don't see the need for using decorators, particularly when I may want exact control over when tasks are added and removed from the queue. Pushing some of the error handling logic into |
fix changed_files + create interface for result revert files to disk version on discard changes or switching branches modify open files on reverting a commit don't overwrite unsaved changes make changed_files more general you can always add the ^! to the commit id. This function isn't currently used anywhere except for this PR so changing this shouldn't break anything update open files on revert commit update tests with mock branches and mock docmanager There may be a better way to mock the docmanager but I can't figure it out add current_path to python tests
3a9a00a
to
548a668
Compare
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.
LGTM Let's merge this
@meeseeksdev backport to 0.11.x |
Owee, I'm MrMeeseeks, Look at me. There seem to be a conflict, please backport manually. Here are approximate instructions:
And apply the correct labels and milestones. Congratulation you did some good work ! Hopefully your backport PR will be tested by the continuous integration and merged soon! If these instruction are inaccurate, feel free to suggest an improvement. |
…11.x Backport PR #676: Update open files when Git commands modify them
Close: #668
If any files are open in jupyterlab that are modified by:
then they will be updated to reflect the new contents. Unless they have unsaved changes, in which case the open document will not be modified.
Approach
Use the
changed_files
command to get the list of files changed by a git command and then revert those files if they are opened.I didn't just loop over all open documents for two reasons:
Tests
I updated the tests to mock the
changed_files
endpoint and mocked thedocmanager
. While my mock of the docmanager seems to work I'm not sure it's the best way to approach the mock. But unfortunately I'm not sure how I ought to do it differently.In action
Swapping branches
Discarding changes
Reverting to a commit
Reverting a specific commit