mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-23 01:22:12 +03:00
use async
This commit is contained in:
parent
22a554d3f4
commit
e4c1329f51
@ -13,154 +13,151 @@ export class BranchController {
|
|||||||
readonly targetBranchStore: Refreshable & Readable<Loadable<Target>>
|
readonly targetBranchStore: Refreshable & Readable<Loadable<Target>>
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
setTarget(branch: string) {
|
async setTarget(branch: string) {
|
||||||
const projectId = this.projectId;
|
try {
|
||||||
return ipc
|
const projectId = this.projectId;
|
||||||
.setTarget({ projectId, branch })
|
await ipc.setTarget({ projectId, branch });
|
||||||
.then(this.virtualBranchStore.refresh)
|
await this.virtualBranchStore.refresh();
|
||||||
.then(this.remoteBranchStore.refresh)
|
await this.remoteBranchStore.refresh();
|
||||||
.catch((err) => {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
toasts.error('Failed to set target');
|
toasts.error('Failed to set target');
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
createBranch(branch: { name?: string; ownership?: string; order?: number }) {
|
async createBranch(branch: { name?: string; ownership?: string; order?: number }) {
|
||||||
const projectId = this.projectId;
|
try {
|
||||||
return ipc
|
const projectId = this.projectId;
|
||||||
.create({ projectId, branch })
|
await ipc.create({ projectId, branch });
|
||||||
.then(this.virtualBranchStore.refresh)
|
await this.virtualBranchStore.refresh();
|
||||||
.catch((err) => {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
toasts.error('Failed to create branch');
|
toasts.error('Failed to create branch');
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
commitBranch(branch: string, message: string) {
|
async commitBranch(branch: string, message: string) {
|
||||||
const projectId = this.projectId;
|
try {
|
||||||
return ipc
|
const projectId = this.projectId;
|
||||||
.commit({ projectId, branch, message })
|
await ipc.commit({ projectId, branch, message });
|
||||||
.then(this.virtualBranchStore.refresh)
|
await this.virtualBranchStore.refresh();
|
||||||
.catch((err) => {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
toasts.error('Failed to commit branch');
|
toasts.error('Failed to commit branch');
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateBranchName(branchId: string, name: string) {
|
async updateBranchName(branchId: string, name: string) {
|
||||||
const projectId = this.projectId;
|
try {
|
||||||
return ipc
|
const projectId = this.projectId;
|
||||||
.update({ projectId, branch: { id: branchId, name } })
|
await ipc.update({ projectId, branch: { id: branchId, name } });
|
||||||
.then(this.virtualBranchStore.refresh)
|
await this.virtualBranchStore.refresh();
|
||||||
.catch((err) => {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
toasts.error('Failed to update branch name');
|
toasts.error('Failed to update branch name');
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateBranchOrder(branchId: string, order: number) {
|
async updateBranchOrder(branchId: string, order: number) {
|
||||||
const projectId = this.projectId;
|
try {
|
||||||
return ipc
|
const projectId = this.projectId;
|
||||||
.update({ projectId, branch: { id: branchId, order } })
|
await ipc.update({ projectId, branch: { id: branchId, order } });
|
||||||
.then(this.virtualBranchStore.refresh)
|
await this.virtualBranchStore.refresh();
|
||||||
.catch((err) => {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
toasts.error('Failed to update branch order');
|
toasts.error('Failed to update branch order');
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
applyBranch(branchId: string) {
|
async applyBranch(branchId: string) {
|
||||||
const projectId = this.projectId;
|
try {
|
||||||
return ipc
|
const projectId = this.projectId;
|
||||||
.apply({ projectId, branch: branchId })
|
await ipc.apply({ projectId, branch: branchId });
|
||||||
.then(this.virtualBranchStore.refresh)
|
await this.virtualBranchStore.refresh();
|
||||||
.catch((err) => {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
toasts.error('Failed to apply branch');
|
toasts.error('Failed to apply branch');
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unapplyBranch(branchId: string) {
|
async unapplyBranch(branchId: string) {
|
||||||
const projectId = this.projectId;
|
try {
|
||||||
return ipc
|
const projectId = this.projectId;
|
||||||
.unapply({ projectId, branch: branchId })
|
await ipc.unapply({ projectId, branch: branchId });
|
||||||
.then(this.virtualBranchStore.refresh)
|
await this.virtualBranchStore.refresh();
|
||||||
.catch((err) => {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
toasts.error('Failed to unapply branch');
|
toasts.error('Failed to unapply branch');
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateBranchOwnership(branchId: string, ownership: string) {
|
async updateBranchOwnership(branchId: string, ownership: string) {
|
||||||
const projectId = this.projectId;
|
try {
|
||||||
return ipc
|
const projectId = this.projectId;
|
||||||
.update({ projectId, branch: { id: branchId, ownership } })
|
await ipc.update({ projectId, branch: { id: branchId, ownership } });
|
||||||
.then(this.virtualBranchStore.refresh)
|
await this.virtualBranchStore.refresh();
|
||||||
.catch((err) => {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
toasts.error('Failed to update branch ownership');
|
toasts.error('Failed to update branch ownership');
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pushBranch(branchId: string) {
|
async pushBranch(branchId: string) {
|
||||||
const projectId = this.projectId;
|
try {
|
||||||
return ipc
|
const projectId = this.projectId;
|
||||||
.push({ projectId, branchId })
|
await ipc.push({ projectId, branchId });
|
||||||
.then(this.virtualBranchStore.refresh)
|
await this.virtualBranchStore.refresh();
|
||||||
.catch((err) => {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
toasts.error('Failed to push branch');
|
toasts.error('Failed to push branch');
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteBranch(branchId: string) {
|
async deleteBranch(branchId: string) {
|
||||||
const projectId = this.projectId;
|
try {
|
||||||
return ipc
|
const projectId = this.projectId;
|
||||||
.delete({ projectId, branchId })
|
await ipc.delete({ projectId, branchId });
|
||||||
.then(this.virtualBranchStore.refresh)
|
await this.virtualBranchStore.refresh();
|
||||||
.then(this.remoteBranchStore.refresh)
|
await this.remoteBranchStore.refresh();
|
||||||
.catch((err) => {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
toasts.error('Failed to delete branch');
|
toasts.error('Failed to delete branch');
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// remote
|
async updateBranchTarget() {
|
||||||
|
try {
|
||||||
updateBranchTarget() {
|
const projectId = this.projectId;
|
||||||
const projectId = this.projectId;
|
await ipc.updateBranchTarget({ projectId });
|
||||||
return ipc
|
await this.remoteBranchStore.refresh();
|
||||||
.updateBranchTarget({ projectId })
|
await this.virtualBranchStore.refresh();
|
||||||
.then(this.remoteBranchStore.refresh)
|
} catch (err) {
|
||||||
.then(this.virtualBranchStore.refresh)
|
console.error(err);
|
||||||
.catch((err) => {
|
toasts.error('Failed to update target');
|
||||||
console.error(err);
|
}
|
||||||
toasts.error('Failed to update target');
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
createvBranchFromBranch(branch: string): Promise<void | string> {
|
async createvBranchFromBranch(branch: string) {
|
||||||
const projectId = this.projectId;
|
try {
|
||||||
const result = ipc.createvBranchFromBranch({ projectId, branch });
|
const projectId = this.projectId;
|
||||||
result.then(this.remoteBranchStore.refresh);
|
await ipc.createvBranchFromBranch({ projectId, branch });
|
||||||
result.then(this.virtualBranchStore.refresh);
|
await this.remoteBranchStore.refresh();
|
||||||
result.catch((err) => {
|
await this.targetBranchStore.refresh();
|
||||||
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
toasts.error('Failed to create virtual branch from branch');
|
toasts.error('Failed to create virtual branch from branch');
|
||||||
});
|
}
|
||||||
// is this return right?
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchFromTarget() {
|
async fetchFromTarget() {
|
||||||
const projectId = this.projectId;
|
try {
|
||||||
return ipc
|
const projectId = this.projectId;
|
||||||
.fetchFromTarget({ projectId })
|
await ipc.fetchFromTarget({ projectId });
|
||||||
.then(this.remoteBranchStore.refresh)
|
await this.remoteBranchStore.refresh();
|
||||||
.then(this.targetBranchStore.refresh)
|
await this.targetBranchStore.refresh();
|
||||||
.catch((err) => {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
toasts.error('Failed to fetch from target');
|
toasts.error('Failed to fetch from target');
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user