Ver a proveniência

Checks for existence of worktree before continuing

Refines remote & worktree revealing
main
Eric Amodio há 1 ano
ascendente
cometimento
e447435925
4 ficheiros alterados com 38 adições e 29 eliminações
  1. +11
    -10
      src/commands/ghpr/createWorktree.ts
  2. +10
    -12
      src/commands/git/remote.ts
  3. +8
    -4
      src/commands/git/worktree.ts
  4. +9
    -3
      src/commands/gitCommands.actions.ts

+ 11
- 10
src/commands/ghpr/createWorktree.ts Ver ficheiro

@ -90,7 +90,7 @@ export class CreateWorktreeCommand extends Command {
);
if (result?.title !== 'Yes') return;
await GitActions.Remote.add(repo, remoteOwner, remoteUrl, { confirm: false, fetch: true });
await GitActions.Remote.add(repo, remoteOwner, remoteUrl, { confirm: false, fetch: true, reveal: false });
[remote] = await repo.getRemotes({ filter: r => r.url === remoteUrl });
if (remote == null) return;
} else {
@ -110,16 +110,17 @@ export class CreateWorktreeCommand extends Command {
}),
);
// Ensure that the worktree was created
const worktree = await this.container.git.getWorktree(repo.path, w => w.branch === ref);
if (worktree == null) return;
// Save the PR number in the branch config
const cfg = await this.container.git.getConfig(repo.path, `branch.${ref}.remote`);
if (cfg != null) {
// https://github.com/Microsoft/vscode-pull-request-github/blob/0c556c48c69a3df2f9cf9a45ed2c40909791b8ab/src/github/pullRequestGitHelper.ts#L18
void this.container.git.setConfig(
repo.path,
`branch.${ref}.github-pr-owner-number`,
`${rootOwner}#${rootRepository}#${number}`,
);
}
// https://github.com/Microsoft/vscode-pull-request-github/blob/0c556c48c69a3df2f9cf9a45ed2c40909791b8ab/src/github/pullRequestGitHelper.ts#L18
void this.container.git.setConfig(
repo.path,
`branch.${ref}.github-pr-owner-number`,
`${rootOwner}#${rootRepository}#${number}`,
);
} catch (ex) {
Logger.error(ex, 'CreateWorktreeCommand', 'Unable to create worktree');
void window.showErrorMessage(`Unable to create worktree for ${ref}`);

+ 10
- 12
src/commands/git/remote.ts Ver ficheiro

@ -42,6 +42,8 @@ interface AddState {
name: string;
url: string;
flags: AddFlags[];
reveal?: boolean;
}
interface RemoveState {
@ -315,18 +317,14 @@ export class RemoteGitCommand extends QuickCommand {
}
QuickCommand.endSteps(state);
const remote = await state.repo.addRemote(
state.name,
state.url,
state.flags.includes('-f') ? { fetch: true } : undefined,
);
queueMicrotask(
() =>
void GitActions.Remote.reveal(remote, {
focus: true,
select: true,
}),
);
await state.repo.addRemote(state.name, state.url, state.flags.includes('-f') ? { fetch: true } : undefined);
if (state.reveal !== false) {
void GitActions.Remote.reveal(undefined, {
focus: true,
select: true,
});
}
}
}

+ 8
- 4
src/commands/git/worktree.ts Ver ficheiro

@ -64,6 +64,8 @@ interface CreateState {
reference?: GitReference;
createBranch: string;
flags: CreateFlags[];
reveal?: boolean;
}
type DeleteFlags = '--force';
@ -383,10 +385,12 @@ export class WorktreeGitCommand extends QuickCommand {
force: state.flags.includes('--force'),
});
void GitActions.Worktree.reveal(worktree, {
select: true,
focus: true,
});
if (state.reveal !== false) {
void GitActions.Worktree.reveal(undefined, {
select: true,
focus: true,
});
}
if (worktree == null) return;

+ 9
- 3
src/commands/gitCommands.actions.ts Ver ficheiro

@ -826,7 +826,7 @@ export namespace GitActions {
repo?: string | Repository,
name?: string,
url?: string,
options?: { confirm?: boolean; fetch?: boolean },
options?: { confirm?: boolean; fetch?: boolean; reveal?: boolean },
) {
return executeGitCommand({
command: 'remote',
@ -837,6 +837,7 @@ export namespace GitActions {
name: name,
url: url,
flags: options?.fetch ? ['-f'] : undefined,
reveal: options?.reveal,
},
});
}
@ -1013,10 +1014,15 @@ export namespace GitActions {
}
export namespace Worktree {
export function create(repo?: string | Repository, uri?: Uri, ref?: GitReference) {
export function create(
repo?: string | Repository,
uri?: Uri,
ref?: GitReference,
options?: { reveal?: boolean },
) {
return executeGitCommand({
command: 'worktree',
state: { subcommand: 'create', repo: repo, uri: uri, reference: ref },
state: { subcommand: 'create', repo: repo, uri: uri, reference: ref, reveal: options?.reveal },
});
}

Carregando…
Cancelar
Guardar