Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rush] Add a more useful error message in cases when a merge base for rush change cannot be determined. #3668

Merged
merged 2 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft/rush",
"comment": "Add a more useful error message in cases when a merge base for `rush change` cannot be determined.",
"type": "none"
}
],
"packageName": "@microsoft/rush"
}
30 changes: 20 additions & 10 deletions libraries/rush-lib/src/logic/Git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,26 @@ export class Git {
}

const gitPath: string = this.getGitPathOrThrow();
const output: string = this._executeGitCommandAndCaptureOutput(gitPath, [
'--no-optional-locks',
'merge-base',
'--',
'HEAD',
targetBranch
]);
const result: string = output.trim();

return result;
try {
const output: string = this._executeGitCommandAndCaptureOutput(gitPath, [
'--no-optional-locks',
'merge-base',
'--',
'HEAD',
targetBranch
]);
const result: string = output.trim();

return result;
} catch (e) {
terminal.writeErrorLine(
`Unable to determine merge base for branch "${targetBranch}". ` +
'This can occur if the current clone is a shallow clone. If this clone is running in a CI ' +
'pipeline, check your pipeline settings to ensure that the clone depth includes ' +
'the expected merge base. If this clone is running locally, consider running "git fetch --deepen=<depth>".'
);
throw new AlreadyReportedError();
}
}

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