From 122c15c4cf7dfe819146b1a878a8c5e7ef99a130 Mon Sep 17 00:00:00 2001 From: Ian Clanton-Thuon Date: Mon, 3 Oct 2022 12:56:47 -0700 Subject: [PATCH 1/2] Add a more useful error message in cases when a merge base for ush change cannot be determined. --- ...-clone-error-message_2022-10-03-19-56.json | 10 +++++++ libraries/rush-lib/src/logic/Git.ts | 30 ++++++++++++------- 2 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 common/changes/@microsoft/rush/shallow-clone-error-message_2022-10-03-19-56.json diff --git a/common/changes/@microsoft/rush/shallow-clone-error-message_2022-10-03-19-56.json b/common/changes/@microsoft/rush/shallow-clone-error-message_2022-10-03-19-56.json new file mode 100644 index 00000000000..1900a93aa0d --- /dev/null +++ b/common/changes/@microsoft/rush/shallow-clone-error-message_2022-10-03-19-56.json @@ -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" +} \ No newline at end of file diff --git a/libraries/rush-lib/src/logic/Git.ts b/libraries/rush-lib/src/logic/Git.ts index 505b9ead651..7bf9f2c919d 100644 --- a/libraries/rush-lib/src/logic/Git.ts +++ b/libraries/rush-lib/src/logic/Git.ts @@ -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".' + ); + throw new AlreadyReportedError(); + } } public getBlobContent({ blobSpec, repositoryRoot }: IGetBlobOptions): string { From b87432e388fd7cb3a370dc7ae7429087fa4a7692 Mon Sep 17 00:00:00 2001 From: Ian Clanton-Thuon Date: Mon, 3 Oct 2022 13:07:54 -0700 Subject: [PATCH 2/2] Clarify a git command. --- libraries/rush-lib/src/logic/Git.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/rush-lib/src/logic/Git.ts b/libraries/rush-lib/src/logic/Git.ts index 7bf9f2c919d..d014dc26ed8 100644 --- a/libraries/rush-lib/src/logic/Git.ts +++ b/libraries/rush-lib/src/logic/Git.ts @@ -246,7 +246,7 @@ export class Git { `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".' + 'the expected merge base. If this clone is running locally, consider running "git fetch --deepen=".' ); throw new AlreadyReportedError(); }