Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions apps/code/src/main/services/git/create-pr-saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,28 @@ export class CreatePrSaga extends Saga<CreatePrSagaInput, CreatePrSagaOutput> {
let { commitMessage, prTitle, prBody } = input;

if (input.branchName) {
this.deps.onProgress(
"creating-branch",
`Creating branch ${input.branchName}...`,
const currentBranch = await this.readOnlyStep("get-original-branch", () =>
this.deps.getCurrentBranch(directoryPath),
);

const originalBranch = await this.readOnlyStep(
"get-original-branch",
() => this.deps.getCurrentBranch(directoryPath),
);
// on retry, do not attempt to re-create the branch
if (currentBranch !== input.branchName) {
this.deps.onProgress(
"creating-branch",
`Creating branch ${input.branchName}...`,
);

await this.step({
name: "creating-branch",
execute: () => this.deps.createBranch(directoryPath, input.branchName!),
rollback: async () => {
if (originalBranch) {
await this.deps.checkoutBranch(directoryPath, originalBranch);
}
},
});
await this.step({
name: "creating-branch",
execute: () =>
this.deps.createBranch(directoryPath, input.branchName!),
rollback: async () => {
if (currentBranch) {
await this.deps.checkoutBranch(directoryPath, currentBranch);
}
},
});
}
}

const changedFiles = await this.readOnlyStep("check-changes", () =>
Expand Down
Loading