Bladeren bron

Clarifies worktree create error handling

main
Eric Amodio 2 jaren geleden
bovenliggende
commit
effb6021eb
3 gewijzigde bestanden met toevoegingen van 25 en 15 verwijderingen
  1. +7
    -8
      src/commands/git/stash.ts
  2. +6
    -7
      src/commands/git/worktree.ts
  3. +12
    -0
      src/git/errors.ts

+ 7
- 8
src/commands/git/stash.ts Bestand weergeven

@ -294,6 +294,7 @@ export class StashGitCommand extends QuickCommand {
}
QuickCommand.endSteps(state);
try {
void (await state.repo.stashApply(
// pop can only take a stash index, e.g. `stash@{1}`
@ -303,14 +304,12 @@ export class StashGitCommand extends QuickCommand {
} catch (ex) {
Logger.error(ex, context.title);
if (ex instanceof StashApplyError) {
if (ex.reason === StashApplyErrorReason.WorkingChanges) {
void window.showWarningMessage(
'Unable to apply stash. Your working tree changes would be overwritten. Please commit or stash your changes before trying again',
);
} else {
void Messages.showGenericErrorMessage(ex.message);
}
if (StashApplyError.is(ex, StashApplyErrorReason.WorkingChanges)) {
void window.showWarningMessage(
'Unable to apply stash. Your working tree changes would be overwritten. Please commit or stash your changes before trying again',
);
} else {
void Messages.showGenericErrorMessage(ex.message);
}
}
}

+ 6
- 7
src/commands/git/worktree.ts Bestand weergeven

@ -367,9 +367,8 @@ export class WorktreeGitCommand extends QuickCommand {
});
} catch (ex) {
if (
!state.flags.includes('--force') &&
ex instanceof WorktreeCreateError &&
ex.reason === WorktreeCreateErrorReason.AlreadyCheckedOut
WorktreeCreateError.is(ex, WorktreeCreateErrorReason.AlreadyCheckedOut) &&
!state.flags.includes('--force')
) {
const createBranch: MessageItem = { title: 'Create New Branch' };
const force: MessageItem = { title: 'Create Anyway' };
@ -398,11 +397,11 @@ export class WorktreeGitCommand extends QuickCommand {
state.confirm = false;
continue;
}
} else if (ex instanceof WorktreeCreateError && ex.reason === WorktreeCreateErrorReason.AlreadyExists) {
void Messages.showGenericErrorMessage(
} else if (WorktreeCreateError.is(ex, WorktreeCreateErrorReason.AlreadyExists)) {
void window.showErrorMessage(
`Unable to create a new worktree in '${GitWorktree.getFriendlyPath(
uri,
)} because that folder already exists.`,
)} because that folder already exists and is not empty.`,
);
} else {
void Messages.showGenericErrorMessage(
@ -610,7 +609,7 @@ export class WorktreeGitCommand extends QuickCommand {
await state.repo.deleteWorktree(uri, { force: force });
} catch (ex) {
if (ex instanceof WorktreeDeleteError) {
if (WorktreeDeleteError.is(ex)) {
if (ex.reason === WorktreeDeleteErrorReason.MainWorkingTree) {
void window.showErrorMessage('Unable to delete the main worktree');
} else if (!force) {

+ 12
- 0
src/git/errors.ts Bestand weergeven

@ -3,6 +3,10 @@ export const enum StashApplyErrorReason {
}
export class StashApplyError extends Error {
static is(ex: any, reason?: StashApplyErrorReason): ex is StashApplyError {
return ex instanceof StashApplyError && (reason == null || ex.reason === reason);
}
readonly original?: Error;
readonly reason: StashApplyErrorReason | undefined;
@ -35,6 +39,10 @@ export const enum WorktreeCreateErrorReason {
}
export class WorktreeCreateError extends Error {
static is(ex: any, reason?: WorktreeCreateErrorReason): ex is WorktreeCreateError {
return ex instanceof WorktreeCreateError && (reason == null || ex.reason === reason);
}
readonly original?: Error;
readonly reason: WorktreeCreateErrorReason | undefined;
@ -73,6 +81,10 @@ export const enum WorktreeDeleteErrorReason {
}
export class WorktreeDeleteError extends Error {
static is(ex: any, reason?: WorktreeDeleteErrorReason): ex is WorktreeDeleteError {
return ex instanceof WorktreeDeleteError && (reason == null || ex.reason === reason);
}
readonly original?: Error;
readonly reason: WorktreeDeleteErrorReason | undefined;

Laden…
Annuleren
Opslaan