-
Notifications
You must be signed in to change notification settings - Fork 639
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
Async await #1358
base: master
Are you sure you want to change the base?
Async await #1358
Changes from all commits
e3cddbd
885a8b2
4601915
f435931
038f465
a63e221
2a92a23
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,11 +133,10 @@ class AppViewModel { | |
); | ||
} | ||
gitSetUserConfig(bugTracking) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For example let's change that here. |
||
this.server.getPromise('/userconfig').then((userConfig) => { | ||
this.server.getPromise('/userconfig').then(async (userConfig) => { | ||
userConfig.bugtracking = bugTracking; | ||
return this.server.postPromise('/userconfig', userConfig).then(() => { | ||
this.bugtrackingEnabled(bugTracking); | ||
}); | ||
await this.server.postPromise('/userconfig', userConfig); | ||
this.bugtrackingEnabled(bugTracking); | ||
}); | ||
} | ||
enableBugtracking() { | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -129,17 +129,21 @@ class BranchesViewModel { | |||||
details: 'Deleting ' + details + ' branch cannot be undone with ungit.', | ||||||
}) | ||||||
.show() | ||||||
.closeThen((diag) => { | ||||||
.closeThen(async (diag) => { | ||||||
if (!diag.result()) return; | ||||||
const url = `${branch.isRemote ? '/remote' : ''}/branches`; | ||||||
return this.server | ||||||
.delPromise(url, { | ||||||
|
||||||
try { | ||||||
await this.server.delPromise(url, { | ||||||
path: this.graph.repoPath(), | ||||||
remote: branch.isRemote ? branch.remote : null, | ||||||
name: branch.refName, | ||||||
}) | ||||||
.then(() => programEvents.dispatch({ event: 'working-tree-changed' })) | ||||||
.catch((e) => this.server.unhandledRejection(e)); | ||||||
}); | ||||||
|
||||||
return programEvents.dispatch({ event: 'working-tree-changed' }); | ||||||
} catch (e) { | ||||||
return this.server.unhandledRejection(e); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it does not return anyting, the rewrite is just using the same returns as before. .catch((e) => this.server.unhandledRejection(e)); did also return |
||||||
} | ||||||
}); | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,7 +99,7 @@ class RefViewModel extends Selectable { | |
this.isDragging(false); | ||
} | ||
|
||
moveTo(target, rewindWarnOverride) { | ||
async moveTo(target, rewindWarnOverride) { | ||
let promise; | ||
if (this.isLocal) { | ||
const toNode = this.graph.nodesById[target]; | ||
|
@@ -161,45 +161,44 @@ class RefViewModel extends Selectable { | |
}); | ||
} | ||
|
||
return promise | ||
.then((res) => { | ||
if (!res) return; | ||
const targetNode = this.graph.getNode(target); | ||
if (this.graph.checkedOutBranch() == this.refName) { | ||
this.graph.HEADref().node(targetNode); | ||
} | ||
this.node(targetNode); | ||
}) | ||
.catch((e) => this.server.unhandledRejection(e)); | ||
try { | ||
const res = await promise; | ||
if (!res) return; | ||
const targetNode = this.graph.getNode(target); | ||
if (this.graph.checkedOutBranch() == this.refName) { | ||
this.graph.HEADref().node(targetNode); | ||
} | ||
this.node(targetNode); | ||
} catch (e) { | ||
return this.server.unhandledRejection(e); | ||
} | ||
} | ||
|
||
remove(isClientOnly) { | ||
async remove(isClientOnly) { | ||
let url = this.isTag ? '/tags' : '/branches'; | ||
if (this.isRemote) url = `/remote${url}`; | ||
|
||
return (isClientOnly | ||
? Promise.resolve() | ||
: this.server.delPromise(url, { | ||
try { | ||
if (!isClientOnly) | ||
await this.server.delPromise(url, { | ||
path: this.graph.repoPath(), | ||
remote: this.isRemote ? this.remote : null, | ||
name: this.refName, | ||
}) | ||
) | ||
.then(() => { | ||
if (this.node()) this.node().removeRef(this); | ||
this.graph.refs.remove(this); | ||
delete this.graph.refsByRefName[this.name]; | ||
}) | ||
.catch((e) => this.server.unhandledRejection(e)) | ||
.finally(() => { | ||
if (!isClientOnly) { | ||
if (url == '/remote/tags') { | ||
programEvents.dispatch({ event: 'request-fetch-tags' }); | ||
} else { | ||
programEvents.dispatch({ event: 'branch-updated' }); | ||
} | ||
}); | ||
|
||
if (this.node()) this.node().removeRef(this); | ||
this.graph.refs.remove(this); | ||
delete this.graph.refsByRefName[this.name]; | ||
} catch (e) { | ||
this.server.unhandledRejection(e); | ||
} finally { | ||
if (!isClientOnly) { | ||
if (url == '/remote/tags') { | ||
programEvents.dispatch({ event: 'request-fetch-tags' }); | ||
} else { | ||
programEvents.dispatch({ event: 'branch-updated' }); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
|
||
getLocalRef() { | ||
|
@@ -241,39 +240,35 @@ class RefViewModel extends Selectable { | |
.catch((e) => this.server.unhandledRejection(e)); | ||
} | ||
|
||
checkout() { | ||
async checkout() { | ||
const isRemote = this.isRemoteBranch; | ||
const isLocalCurrent = this.getLocalRef() && this.getLocalRef().current(); | ||
|
||
return Promise.resolve() | ||
.then(() => { | ||
if (isRemote && !isLocalCurrent) { | ||
return this.server.postPromise('/branches', { | ||
path: this.graph.repoPath(), | ||
name: this.refName, | ||
sha1: this.name, | ||
force: true, | ||
}); | ||
} | ||
}) | ||
.then(() => | ||
this.server.postPromise('/checkout', { path: this.graph.repoPath(), name: this.refName }) | ||
) | ||
.then(() => { | ||
if (isRemote && isLocalCurrent) { | ||
return this.server.postPromise('/reset', { | ||
path: this.graph.repoPath(), | ||
to: this.name, | ||
mode: 'hard', | ||
}); | ||
} | ||
}) | ||
.then(() => { | ||
this.graph.HEADref().node(this.node()); | ||
}) | ||
.catch((err) => { | ||
if (err.errorCode != 'merge-failed') this.server.unhandledRejection(err); | ||
try { | ||
if (isRemote && !isLocalCurrent) { | ||
return this.server.postPromise('/branches', { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is actually wrong, because |
||
path: this.graph.repoPath(), | ||
name: this.refName, | ||
sha1: this.name, | ||
force: true, | ||
}); | ||
} | ||
await this.server.postPromise('/checkout', { | ||
path: this.graph.repoPath(), | ||
name: this.refName, | ||
}); | ||
if (isRemote && isLocalCurrent) { | ||
return this.server.postPromise('/reset', { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is actually wrong, because |
||
path: this.graph.repoPath(), | ||
to: this.name, | ||
mode: 'hard', | ||
}); | ||
} | ||
|
||
this.graph.HEADref().node(this.node()); | ||
} catch (err) { | ||
if (err.errorCode != 'merge-failed') this.server.unhandledRejection(err); | ||
} | ||
} | ||
} | ||
|
||
|
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.
The whole
clickParallel
task still has a bunch ofthen
. Why is only this part rewritten?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.
It looks like promises which are not returned in a function are not going to be rewritten because that would change the return type to be a
Promise
instead ofvoid
.This is fine in some places like here but we might want do change that in other places.