8000 Add a more useful error message in cases when a merge base for ush c… · mstomar698/rushstack@122c15c · GitHub
[go: up one dir, main page]

Skip to content

Commit 122c15c

Browse files
committed
Add a more useful error message in cases when a merge base for ush change cannot be determined.
1 parent a725488 commit 122c15c

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/rush",
5+
"comment": "Add a more useful error message in cases when a merge base for `rush change` cannot be determined.",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@microsoft/rush"
10+
}

libraries/rush-lib/src/logic/Git.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -230,16 +230,26 @@ export class Git {
230230
}
231231

232232
const gitPath: string = this.getGitPathOrThrow();
233-
const output: string = this._executeGitCommandAndCaptureOutput(gitPath, [
234-
'--no-optional-locks',
235-
'merge-base',
236-
'--',
237-
'HEAD',
238-
targetBranch
239-
]);
240-
const result: string = output.trim();
241-
242-
return result;
233+
try {
234+
const output: string = this._executeGitCommandAndCaptureOutput(gitPath, [
235+
'--no-optional-locks',
236+
'merge-base',
237+
'--',
238+
'HEAD',
239+
targetBranch
240+
]);
241+
const result: string = output.trim();
242+
243+
return result;
244+
} catch (e) {
245+
terminal.writeErrorLine(
246+
`Unable to determine merge base for branch "${targetBranch}". ` +
247+
'This can occur if the current clone is a shallow clone. If this clone is running in a CI ' +
248+
'pipeline, check your pipeline settings to ensure that the clone depth includes ' +
249+
'the expected merge base. If this clone is running locally, consider running "git fetch --deepen".'
250+
);
251+
throw new AlreadyReportedError();
252+
}
243253
}
244254

245255
public getBlobContent({ blobSpec, repositoryRoot }: IGetBlobOptions): string {

0 commit comments

Comments
 (0)
0