Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit d821930

Browse files
committed
fix: unable to determine first commit
If first commit on current branch could not be determined then master is taken as fallback. This assumes that the commits to put into the pull request are commit on master and then a branch is created. It will be inaccurate to chose the correct title and body if there are multiple commits on master, since it is impossible to select the first commit (maybe it would be good to diff against origin/master and select the first commit between orgin/master and master in that case).
1 parent b081b62 commit d821930

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/git.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,14 @@ export class Git {
117117
}
118118

119119
public async getFirstCommitOnBranch(branch: string, defaultBranch: string, uri: vscode.Uri): Promise<string> {
120-
return (await this.execute(`git rev-list ^${defaultBranch} ${branch}`, uri)).stdout.trim().split('\n')[0];
120+
const sha = (await this.execute(`git rev-list ^${defaultBranch} ${branch}`, uri)).stdout.trim().split('\n')[0];
121+
if (!sha) {
122+
return 'master';
123+
}
124+
return sha;
121125
}
122126

123-
public async getCommitBody(sha: string, uri: vscode.Uri): Promise<string> {
127+
private async getCommitBody(sha: string, uri: vscode.Uri): Promise<string> {
124128
return (await this.execute(`git log --format=%b -n 1 ${sha}`, uri)).stdout.trim();
125129
}
126130

0 commit comments

Comments
 (0)