豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit 5e1f351

Browse files
committed
fix(ng-dev/pr): Move the cleanup of the merge attempt to the finally block (#216)
Move the cleanup of the merge attempt to the finally block to ensure that the cleanup of the generated branches occurs regardless of the success of the merge attempt. PR Close #216
1 parent 0c43579 commit 5e1f351

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

ng-dev/pr/merge/task.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,11 @@ export class PullRequestMergeTask {
130130

131131
// Branch or revision that is currently checked out so that we can switch back to
132132
// it once the pull request has been merged.
133-
let previousBranchOrRevision: null | string = null;
133+
const previousBranchOrRevision = this.git.getCurrentBranchOrRevision();
134134

135135
// The following block runs Git commands as child processes. These Git commands can fail.
136136
// We want to capture these command errors and return an appropriate merge request status.
137137
try {
138-
previousBranchOrRevision = this.git.getCurrentBranchOrRevision();
139-
140138
// Run preparations for the merge (e.g. fetching branches).
141139
await strategy.prepare(pullRequest);
142140

@@ -146,12 +144,6 @@ export class PullRequestMergeTask {
146144
return {status: MergeStatus.FAILED, failure};
147145
}
148146

149-
// Switch back to the previous branch. We need to do this before deleting the temporary
150-
// branches because we cannot delete branches which are currently checked out.
151-
this.git.run(['checkout', '-f', previousBranchOrRevision]);
152-
153-
await strategy.cleanup(pullRequest);
154-
155147
// Return a successful merge status.
156148
return {status: MergeStatus.SUCCESS};
157149
} catch (e) {
@@ -162,11 +154,11 @@ export class PullRequestMergeTask {
162154
}
163155
throw e;
164156
} finally {
165-
// Always try to restore the branch if possible. We don't want to leave
166-
// the repository in a different state than before.
167-
if (previousBranchOrRevision !== null) {
168-
this.git.runGraceful(['checkout', '-f', previousBranchOrRevision]);
169-
}
157+
// Switch back to the previous branch. We need to do this before deleting the temporary
158+
// branches because we cannot delete branches which are currently checked out.
159+
this.git.run(['checkout', '-f', previousBranchOrRevision]);
160+
161+
await strategy.cleanup(pullRequest);
170162
}
171163
}
172164
}

0 commit comments

Comments
 (0)