提交 99ce8b1b 编写于 作者: P Peng Lyu

fetch from the pr branch directly

上级 9045d454
......@@ -250,6 +250,26 @@ export class Repository {
return '';
}
}
async checkoutPR(pr: PullRequest) {
let cloneUrl = pr.prItem.head.repo.clone_url;
let result = await GitProcess.exec(['remote', 'add', `pull/${pr.prItem.number}`, cloneUrl], this.path);
if (result.exitCode !== 0) {
throw (result.exitCode);
}
result = await GitProcess.exec(['fetch', `pull/${pr.prItem.number}`], this.path);
if (result.exitCode !== 0) {
throw (result.exitCode);
}
result = await GitProcess.exec(['checkout', '-b', `pull-request-${pr.prItem.number}`, '--track', `pull/${pr.prItem.number}/${pr.prItem.head.ref}`], this.path);
if (result.exitCode !== 0) {
throw (result.exitCode);
}
}
}
export class GitHubRepository {
......
......@@ -99,8 +99,8 @@ export class ReviewMode {
change.fileName,
change.status,
change.fileName,
toGitUri(vscode.Uri.parse(change.fileName), null, change.status === GitChangeType.DELETE ? '' : state.head.sha, {}),
toGitUri(vscode.Uri.parse(change.fileName), null, change.status === GitChangeType.ADD ? '' : state.base.sha, {}),
toGitUri(vscode.Uri.parse(change.fileName), null, change.status === GitChangeType.DELETE ? '' : pr.prItem.head.sha, {}),
toGitUri(vscode.Uri.parse(change.fileName), null, change.status === GitChangeType.ADD ? '' : pr.prItem.base.sha, {}),
this._repository.path,
change.patch
);
......@@ -242,8 +242,12 @@ export class ReviewMode {
async switch(pr: PullRequest) {
try {
await this._repository.fetch(pr.remote.remoteName, `pull/${pr.prItem.number}/head:pull-request-${pr.prItem.number}`);
await this._repository.checkout(`pull-request-${pr.prItem.number}`);
if (pr.prItem.maintainer_can_modify) {
await this._repository.checkoutPR(pr);
} else {
await this._repository.fetch(pr.remote.remoteName, `pull/${pr.prItem.number}/head:pull-request-${pr.prItem.number}`);
await this._repository.checkout(`pull-request-${pr.prItem.number}`);
}
} catch (e) {
vscode.window.showErrorMessage(e);
return;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册