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:
parent
71fa896a91
commit
49c3ce58bf
@ -172,7 +172,7 @@ var GitCommandError = /** @class */ (function (_super) {
|
|||||||
var GitClient = /** @class */ (function () {
|
var GitClient = /** @class */ (function () {
|
||||||
/**
|
/**
|
||||||
* @param githubToken The github token used for authentication, if provided.
|
* @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.
|
* @param baseDir The full path to the root of the repository base.
|
||||||
*/
|
*/
|
||||||
function GitClient(githubToken, config, baseDir) {
|
function GitClient(githubToken, config, baseDir) {
|
||||||
@ -294,10 +294,6 @@ var GitClient = /** @class */ (function () {
|
|||||||
GitClient.prototype.hasUncommittedChanges = function () {
|
GitClient.prototype.hasUncommittedChanges = function () {
|
||||||
return this.runGraceful(['diff-index', '--quiet', 'HEAD']).status !== 0;
|
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. */
|
/** Sanitizes a given message by omitting the provided Github token if present. */
|
||||||
GitClient.prototype.omitGithubTokenFromMessage = function (value) {
|
GitClient.prototype.omitGithubTokenFromMessage = function (value) {
|
||||||
// If no token has been defined (i.e. no token regex), we just return the
|
// If no token has been defined (i.e. no token regex), we just return the
|
||||||
|
@ -340,7 +340,7 @@ var GitCommandError = /** @class */ (function (_super) {
|
|||||||
var GitClient = /** @class */ (function () {
|
var GitClient = /** @class */ (function () {
|
||||||
/**
|
/**
|
||||||
* @param githubToken The github token used for authentication, if provided.
|
* @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.
|
* @param baseDir The full path to the root of the repository base.
|
||||||
*/
|
*/
|
||||||
function GitClient(githubToken, config, baseDir) {
|
function GitClient(githubToken, config, baseDir) {
|
||||||
@ -462,10 +462,6 @@ var GitClient = /** @class */ (function () {
|
|||||||
GitClient.prototype.hasUncommittedChanges = function () {
|
GitClient.prototype.hasUncommittedChanges = function () {
|
||||||
return this.runGraceful(['diff-index', '--quiet', 'HEAD']).status !== 0;
|
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. */
|
/** Sanitizes a given message by omitting the provided Github token if present. */
|
||||||
GitClient.prototype.omitGithubTokenFromMessage = function (value) {
|
GitClient.prototype.omitGithubTokenFromMessage = function (value) {
|
||||||
// If no token has been defined (i.e. no token regex), we just return the
|
// 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();
|
const git = GitClient.getAuthenticatedInstance();
|
||||||
// In order to preserve local changes, checkouts cannot occur if local changes are present in the
|
// 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.
|
// 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.');
|
throw new UnexpectedLocalChangesError('Unable to checkout PR due to uncommitted changes.');
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -3250,7 +3246,7 @@ function discoverNewConflictsForPr(newPrNumber, updatedAfter) {
|
|||||||
const git = GitClient.getAuthenticatedInstance();
|
const git = GitClient.getAuthenticatedInstance();
|
||||||
// If there are any local changes in the current repository state, the
|
// If there are any local changes in the current repository state, the
|
||||||
// check cannot run as it needs to move between branches.
|
// 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.');
|
error('Cannot run with local changes. Please make sure there are no local changes.');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
@ -4582,8 +4578,7 @@ function rebasePr(prNumber, githubToken, config = getConfig()) {
|
|||||||
return tslib.__awaiter(this, void 0, void 0, function* () {
|
return tslib.__awaiter(this, void 0, void 0, function* () {
|
||||||
/** The singleton instance of the GitClient. */
|
/** The singleton instance of the GitClient. */
|
||||||
const git = GitClient.getAuthenticatedInstance();
|
const git = GitClient.getAuthenticatedInstance();
|
||||||
// TODO: Rely on a common assertNoLocalChanges function.
|
if (git.hasUncommittedChanges()) {
|
||||||
if (git.hasLocalChanges()) {
|
|
||||||
error('Cannot perform rebase of PR with local changes.');
|
error('Cannot perform rebase of PR with local changes.');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ export async function checkOutPullRequestLocally(
|
|||||||
|
|
||||||
// In order to preserve local changes, checkouts cannot occur if local changes are present in the
|
// 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.
|
// 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.');
|
throw new UnexpectedLocalChangesError('Unable to checkout PR due to uncommitted changes.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ export async function discoverNewConflictsForPr(newPrNumber: number, updatedAfte
|
|||||||
const git = GitClient.getAuthenticatedInstance();
|
const git = GitClient.getAuthenticatedInstance();
|
||||||
// If there are any local changes in the current repository state, the
|
// If there are any local changes in the current repository state, the
|
||||||
// check cannot run as it needs to move between branches.
|
// 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.');
|
error('Cannot run with local changes. Please make sure there are no local changes.');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
@ -46,8 +46,7 @@ export async function rebasePr(
|
|||||||
prNumber: number, githubToken: string, config: Pick<NgDevConfig, 'github'> = getConfig()) {
|
prNumber: number, githubToken: string, config: Pick<NgDevConfig, 'github'> = getConfig()) {
|
||||||
/** The singleton instance of the GitClient. */
|
/** The singleton instance of the GitClient. */
|
||||||
const git = GitClient.getAuthenticatedInstance();
|
const git = GitClient.getAuthenticatedInstance();
|
||||||
// TODO: Rely on a common assertNoLocalChanges function.
|
if (git.hasUncommittedChanges()) {
|
||||||
if (git.hasLocalChanges()) {
|
|
||||||
error('Cannot perform rebase of PR with local changes.');
|
error('Cannot perform rebase of PR with local changes.');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ export class GitClient<Authenticated extends boolean> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param githubToken The github token used for authentication, if provided.
|
* @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.
|
* @param baseDir The full path to the root of the repository base.
|
||||||
*/
|
*/
|
||||||
protected constructor(public githubToken: Authenticated extends true? string: undefined,
|
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;
|
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. */
|
/** Sanitizes a given message by omitting the provided Github token if present. */
|
||||||
omitGithubTokenFromMessage(value: string): string {
|
omitGithubTokenFromMessage(value: string): string {
|
||||||
// If no token has been defined (i.e. no token regex), we just return the
|
// If no token has been defined (i.e. no token regex), we just return the
|
||||||
|
Loading…
x
Reference in New Issue
Block a user