refactor(dev-infra): remove duplicate method that checks for uncommitted changes (#42409)

Removes the duplicate `hasLocalChanges` method from the Git client. We
already have `hasUncommittedChanges`. Also removes a TODO for adding
`assertNoLocalChanges` as it seems more flexible to manually check
(i.e. better messaging with context on the current tool; e.g. "cannot
perform rebase")

PR Close #42409
This commit is contained in:
Paul Gschwendtner 2021-05-28 14:20:18 +02:00 committed by Jessica Janiuk
parent 71fa896a91
commit 49c3ce58bf
6 changed files with 9 additions and 24 deletions

View File

@ -172,7 +172,7 @@ var GitCommandError = /** @class */ (function (_super) {
var GitClient = /** @class */ (function () {
/**
* @param githubToken The github token used for authentication, if provided.
* @param _config The configuration, containing the github specific configuration.
* @param config The configuration, containing the github specific configuration.
* @param baseDir The full path to the root of the repository base.
*/
function GitClient(githubToken, config, baseDir) {
@ -294,10 +294,6 @@ var GitClient = /** @class */ (function () {
GitClient.prototype.hasUncommittedChanges = function () {
return this.runGraceful(['diff-index', '--quiet', 'HEAD']).status !== 0;
};
/** Whether the repo has any local changes. */
GitClient.prototype.hasLocalChanges = function () {
return this.runGraceful(['diff-index', '--quiet', 'HEAD']).status !== 0;
};
/** Sanitizes a given message by omitting the provided Github token if present. */
GitClient.prototype.omitGithubTokenFromMessage = function (value) {
// If no token has been defined (i.e. no token regex), we just return the

View File

@ -340,7 +340,7 @@ var GitCommandError = /** @class */ (function (_super) {
var GitClient = /** @class */ (function () {
/**
* @param githubToken The github token used for authentication, if provided.
* @param _config The configuration, containing the github specific configuration.
* @param config The configuration, containing the github specific configuration.
* @param baseDir The full path to the root of the repository base.
*/
function GitClient(githubToken, config, baseDir) {
@ -462,10 +462,6 @@ var GitClient = /** @class */ (function () {
GitClient.prototype.hasUncommittedChanges = function () {
return this.runGraceful(['diff-index', '--quiet', 'HEAD']).status !== 0;
};
/** Whether the repo has any local changes. */
GitClient.prototype.hasLocalChanges = function () {
return this.runGraceful(['diff-index', '--quiet', 'HEAD']).status !== 0;
};
/** Sanitizes a given message by omitting the provided Github token if present. */
GitClient.prototype.omitGithubTokenFromMessage = function (value) {
// If no token has been defined (i.e. no token regex), we just return the
@ -3110,7 +3106,7 @@ function checkOutPullRequestLocally(prNumber, githubToken, opts = {}) {
const git = GitClient.getAuthenticatedInstance();
// In order to preserve local changes, checkouts cannot occur if local changes are present in the
// git environment. Checked before retrieving the PR to fail fast.
if (git.hasLocalChanges()) {
if (git.hasUncommittedChanges()) {
throw new UnexpectedLocalChangesError('Unable to checkout PR due to uncommitted changes.');
}
/**
@ -3250,7 +3246,7 @@ function discoverNewConflictsForPr(newPrNumber, updatedAfter) {
const git = GitClient.getAuthenticatedInstance();
// If there are any local changes in the current repository state, the
// check cannot run as it needs to move between branches.
if (git.hasLocalChanges()) {
if (git.hasUncommittedChanges()) {
error('Cannot run with local changes. Please make sure there are no local changes.');
process.exit(1);
}
@ -4582,8 +4578,7 @@ function rebasePr(prNumber, githubToken, config = getConfig()) {
return tslib.__awaiter(this, void 0, void 0, function* () {
/** The singleton instance of the GitClient. */
const git = GitClient.getAuthenticatedInstance();
// TODO: Rely on a common assertNoLocalChanges function.
if (git.hasLocalChanges()) {
if (git.hasUncommittedChanges()) {
error('Cannot perform rebase of PR with local changes.');
process.exit(1);
}

View File

@ -67,7 +67,7 @@ export async function checkOutPullRequestLocally(
// In order to preserve local changes, checkouts cannot occur if local changes are present in the
// git environment. Checked before retrieving the PR to fail fast.
if (git.hasLocalChanges()) {
if (git.hasUncommittedChanges()) {
throw new UnexpectedLocalChangesError('Unable to checkout PR due to uncommitted changes.');
}

View File

@ -57,7 +57,7 @@ export async function discoverNewConflictsForPr(newPrNumber: number, updatedAfte
const git = GitClient.getAuthenticatedInstance();
// If there are any local changes in the current repository state, the
// check cannot run as it needs to move between branches.
if (git.hasLocalChanges()) {
if (git.hasUncommittedChanges()) {
error('Cannot run with local changes. Please make sure there are no local changes.');
process.exit(1);
}

View File

@ -46,8 +46,7 @@ export async function rebasePr(
prNumber: number, githubToken: string, config: Pick<NgDevConfig, 'github'> = getConfig()) {
/** The singleton instance of the GitClient. */
const git = GitClient.getAuthenticatedInstance();
// TODO: Rely on a common assertNoLocalChanges function.
if (git.hasLocalChanges()) {
if (git.hasUncommittedChanges()) {
error('Cannot perform rebase of PR with local changes.');
process.exit(1);
}

View File

@ -115,7 +115,7 @@ export class GitClient<Authenticated extends boolean> {
/**
* @param githubToken The github token used for authentication, if provided.
* @param _config The configuration, containing the github specific configuration.
* @param config The configuration, containing the github specific configuration.
* @param baseDir The full path to the root of the repository base.
*/
protected constructor(public githubToken: Authenticated extends true? string: undefined,
@ -214,11 +214,6 @@ export class GitClient<Authenticated extends boolean> {
return this.runGraceful(['diff-index', '--quiet', 'HEAD']).status !== 0;
}
/** Whether the repo has any local changes. */
hasLocalChanges(): boolean {
return this.runGraceful(['diff-index', '--quiet', 'HEAD']).status !== 0;
}
/** Sanitizes a given message by omitting the provided Github token if present. */
omitGithubTokenFromMessage(value: string): string {
// If no token has been defined (i.e. no token regex), we just return the