Skip to content

Commit

Permalink
rebase & lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiolms committed Nov 7, 2024
1 parent 0c17c53 commit 3adc472
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 24 deletions.
39 changes: 19 additions & 20 deletions src/env/node/git/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,39 +74,38 @@ const textDecoder = new TextDecoder('utf8');
const rootSha = '4b825dc642cb6eb9a060e54bf8d69288fbee4904';

export const GitErrors = {
alreadyCheckedOut: /already checked out/i,
alreadyExists: /already exists/i,
ambiguousArgument: /fatal:\s*ambiguous argument ['"].+['"]: unknown revision or path not in the working tree/i,
badRevision: /bad revision '(.*?)'/i,
cantLockRef: /cannot lock ref|unable to update local ref/i,
changesWouldBeOverwritten: /Your local changes to the following files would be overwritten/i,
commitChangesFirst: /Please, commit your changes before you can/i,
conflict: /^CONFLICT \([^)]+\): \b/m,
entryNotUpToDate: /error:\s*Entry ['"].+['"] not uptodate\. Cannot merge\./i,
failedToDeleteDirectoryNotEmpty: /failed to delete '(.*?)': Directory not empty/i,
invalidLineCount: /file .+? has only \d+ lines/i,
invalidObjectName: /invalid object name: (.*)\s/i,
invalidObjectNameList: /could not open object name list: (.*)\s/i,
mainWorkingTree: /is a main working tree/i,
noFastForward: /\(non-fast-forward\)/i,
noMergeBase: /no merge base/i,
noRemoteRepositorySpecified: /No remote repository specified\./i,
noUpstream: /^fatal: The current branch .* has no upstream branch/i,
noUserNameConfigured: /Please tell me who you are\./i,
notAValidObjectName: /Not a valid object name/i,
notAWorkingTree: /'(.*?)' is not a working tree/i,
noUserNameConfigured: /Please tell me who you are\./i,
invalidLineCount: /file .+? has only \d+ lines/i,
uncommittedChanges: /contains modified or untracked files/i,
alreadyExists: /already exists/i,
alreadyCheckedOut: /already checked out/i,
mainWorkingTree: /is a main working tree/i,
noUpstream: /^fatal: The current branch .* has no upstream branch/i,
permissionDenied: /Permission.*denied/i,
pushRejected: /^error: failed to push some refs to\b/m,
rebaseMultipleBranches: /cannot rebase onto multiple branches/i,
refLocked: /fatal:\s*cannot lock ref ['"].+['"]: unable to create file/i,
remoteAhead: /rejected because the remote contains work/i,
remoteConnection: /Could not read from remote repository/i,
tagConflict: /! \[rejected\].*\(would clobber existing tag\)/m,
uncommittedChanges: /contains modified or untracked files/i,
unmergedChanges: /error:\s*you need to resolve your current index first/i,
unmergedFiles: /is not possible because you have unmerged files/i,
unstagedChanges: /You have unstaged changes/i,
unmergedChanges: /error:\s*you need to resolve your current index first/i,
ambiguousArgument: /fatal:\s*ambiguous argument ['"].+['"]: unknown revision or path not in the working tree/i,
entryNotUpToDate: /error:\s*Entry ['"].+['"] not uptodate\. Cannot merge\./i,
changesWouldBeOverwritten: /error:\s*Your local changes to the following files would be overwritten/i,
refLocked: /fatal:\s*cannot lock ref ['"].+['"]: unable to create file/i,
};

const GitWarnings = {
Expand Down Expand Up @@ -167,12 +166,12 @@ function getStdinUniqueKey(): number {
type ExitCodeOnlyGitCommandOptions = GitCommandOptions & { exitCodeOnly: true };
export type PushForceOptions = { withLease: true; ifIncludes?: boolean } | { withLease: false; ifIncludes?: never };

const resetErrorAndReason = [
[unmergedChanges, ResetErrorReason.UnmergedChanges],
[ambiguousArgument, ResetErrorReason.AmbiguousArgument],
[entryNotUpToDate, ResetErrorReason.EntryNotUpToDate],
[changesWouldBeOverwritten, ResetErrorReason.LocalChangesWouldBeOverwritten],
[refLocked, ResetErrorReason.RefLocked],
const resetErrorAndReason: [RegExp, ResetErrorReason][] = [
[GitErrors.unmergedChanges, ResetErrorReason.UnmergedChanges],
[GitErrors.ambiguousArgument, ResetErrorReason.AmbiguousArgument],
[GitErrors.entryNotUpToDate, ResetErrorReason.EntryNotUpToDate],
[GitErrors.changesWouldBeOverwritten, ResetErrorReason.LocalChangesWouldBeOverwritten],
[GitErrors.refLocked, ResetErrorReason.RefLocked],
];

export class Git {
Expand Down Expand Up @@ -1586,9 +1585,9 @@ export class Git {
return this.git<string>({ cwd: repoPath }, 'remote', 'get-url', remote);
}

reset(repoPath: string, pathspecs: string[], ...args: string[]) {
async reset(repoPath: string, pathspecs: string[], ...args: string[]) {
try {
return this.git<string>({ cwd: repoPath }, 'reset', '-q', ...args, '--', ...pathspecs);
await this.git<string>({ cwd: repoPath }, 'reset', '-q', ...args, '--', ...pathspecs);
} catch (ex) {
const msg: string = ex?.toString() ?? '';
for (const [error, reason] of resetErrorAndReason) {
Expand Down
2 changes: 1 addition & 1 deletion src/env/node/git/localGitProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5789,7 +5789,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
}

@log()
async reset(repoPath: string, options?: { hard?: boolean; soft?: boolean }, ref?: string): Promise<void> {
async reset(repoPath: string, ref: string, options?: { hard?: boolean; soft?: boolean }): Promise<void> {
const flags = [];
if (options?.hard) {
flags.push('--hard');
Expand Down
2 changes: 1 addition & 1 deletion src/git/gitProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export interface GitProviderRepository {
pruneRemote?(repoPath: string, name: string): Promise<void>;
removeRemote?(repoPath: string, name: string): Promise<void>;

reset?(repoPath: string, options?: { hard?: boolean; soft?: boolean }, ref?: string): Promise<void>;
reset?(repoPath: string, ref: string, options?: { hard?: boolean; soft?: boolean }): Promise<void>;

applyUnreachableCommitForPatch?(
repoPath: string,
Expand Down
4 changes: 2 additions & 2 deletions src/git/gitProviderService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1335,7 +1335,7 @@ export class GitProviderService implements Disposable {
}

@log()
async reset(repoPath: string, flags: string[], ref?: string): Promise<void> {
async reset(repoPath: string, flags: string[], ref: string): Promise<void> {
const { provider, path } = this.getProvider(repoPath);
if (provider.reset == null) throw new ProviderNotSupportedError(provider.descriptor.name);

Expand All @@ -1353,7 +1353,7 @@ export class GitProviderService implements Disposable {
}
}

return provider.reset(path, options, ref);
return provider.reset(path, ref, options);
}

@log()
Expand Down

0 comments on commit 3adc472

Please sign in to comment.