Kaynağa Gözat

Checks for existence of worktree before continuing

Refines remote & worktree revealing
main
Eric Amodio 1 yıl önce
ebeveyn
işleme
e447435925
4 değiştirilmiş dosya ile 38 ekleme ve 29 silme
  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 Dosyayı Görüntüle

@ -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 Dosyayı Görüntüle

@ -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 Dosyayı Görüntüle

@ -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 Dosyayı Görüntüle

@ -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 },
});
}

Yükleniyor…
İptal
Kaydet