Ver a proveniência

Applies patch to branch

main
Keith Daulton há 1 ano
ascendente
cometimento
30fa830207
7 ficheiros alterados com 113 adições e 8 eliminações
  1. +33
    -4
      src/plus/webviews/patchDetails/patchDetailsWebview.ts
  2. +1
    -0
      src/plus/webviews/patchDetails/protocol.ts
  3. +51
    -0
      src/quickpicks/branchPicker.ts
  4. +18
    -2
      src/webviews/apps/plus/patchDetails/components/gl-draft-details.ts
  5. +4
    -0
      src/webviews/apps/plus/patchDetails/patchDetails.scss
  6. +5
    -1
      src/webviews/apps/plus/patchDetails/patchDetails.ts
  7. +1
    -1
      src/webviews/apps/shared/components/webview-pane.ts

+ 33
- 4
src/plus/webviews/patchDetails/patchDetailsWebview.ts Ver ficheiro

@ -1,7 +1,7 @@
import type { ConfigurationChangeEvent } from 'vscode';
import { Disposable, env, Uri, window } from 'vscode';
import type { CoreConfiguration } from '../../../constants';
import { Commands } from '../../../constants';
import { Commands, GlyphChars } from '../../../constants';
import type { Container } from '../../../container';
import { openChanges, openChangesWithWorking, openFile } from '../../../git/actions/commit';
import type { RepositoriesChangeEvent } from '../../../git/gitProviderService';
@ -13,6 +13,7 @@ import { createReference } from '../../../git/models/reference';
import { isRepository } from '../../../git/models/repository';
import type { CreateDraftChange, Draft, DraftPatch, DraftPatchFileChange, LocalDraft } from '../../../gk/models/drafts';
import type { GkRepositoryId } from '../../../gk/models/repositoryIdentities';
import { showBranchPicker } from '../../../quickpicks/branchPicker';
import { executeCommand, registerCommand } from '../../../system/command';
import { configuration } from '../../../system/configuration';
import { setContext } from '../../../system/context';
@ -321,6 +322,8 @@ export class PatchDetailsWebviewProvider
const changeset = this._context.draft.changesets?.[0];
if (changeset == null) return;
// TODO: should be overridable with targetRef
const shouldPickBranch = params.target === 'branch';
for (const patch of changeset.patches) {
if (!params.selected.includes(patch.id)) continue;
@ -335,9 +338,35 @@ export class PatchDetailsWebviewProvider
continue;
}
void this.container.git.applyPatchCommit(commit.repoPath, commit.ref, {
branchName: patch.baseBranchName,
});
let options:
| {
branchName?: string;
createBranchIfNeeded?: boolean;
createWorktreePath?: string;
}
| undefined = undefined;
if (shouldPickBranch) {
const repo = commit.getRepository();
const branch = await showBranchPicker(
`Choose a Branch ${GlyphChars.Dot} ${repo?.name}`,
'Choose a branch to apply the Cloud Patch to',
repo,
);
if (branch == null) {
void window.showErrorMessage(
`Unable apply patch to '${patch.repository!.name}': No branch selected`,
);
continue;
}
options = {
branchName: branch.ref,
createBranchIfNeeded: true,
};
}
void this.container.git.applyPatchCommit(commit.repoPath, commit.ref, options);
} catch (ex) {
void window.showErrorMessage(`Unable apply patch to '${patch.baseRef}': ${ex.message}`);
}

+ 1
- 0
src/plus/webviews/patchDetails/protocol.ts Ver ficheiro

@ -168,6 +168,7 @@ export type ShowCommitDetailsViewCommandArgs = string[];
export interface ApplyPatchParams {
details: DraftDetails;
targetRef?: string; // a branch name. default to HEAD if not supplied
target: 'current' | 'branch' | 'worktree';
selected: PatchDetails['id'][];
}
export const ApplyPatchCommandType = new IpcCommandType<ApplyPatchParams>('patch/apply');

+ 51
- 0
src/quickpicks/branchPicker.ts Ver ficheiro

@ -0,0 +1,51 @@
import type { Disposable } from 'vscode';
import { window } from 'vscode';
import { getBranches } from '../commands/quickCommand.steps';
import type { Repository } from '../git/models/repository';
import { getQuickPickIgnoreFocusOut } from '../system/utils';
import type { BranchQuickPickItem } from './items/gitCommands';
export async function showBranchPicker(
title: string | undefined,
placeholder?: string,
repository?: Repository,
): Promise<BranchQuickPickItem | undefined> {
if (repository == null) {
return undefined;
}
const items: BranchQuickPickItem[] = await getBranches(repository, {});
if (items.length === 0) return undefined;
const quickpick = window.createQuickPick<BranchQuickPickItem>();
quickpick.ignoreFocusOut = getQuickPickIgnoreFocusOut();
const disposables: Disposable[] = [];
try {
const pick = await new Promise<BranchQuickPickItem | undefined>(resolve => {
disposables.push(
quickpick.onDidHide(() => resolve(undefined)),
quickpick.onDidAccept(() => {
if (quickpick.activeItems.length !== 0) {
resolve(quickpick.activeItems[0]);
}
}),
);
quickpick.title = title;
quickpick.placeholder = placeholder;
quickpick.matchOnDescription = true;
quickpick.matchOnDetail = true;
quickpick.items = items;
quickpick.show();
});
if (pick == null) return undefined;
return pick;
} finally {
quickpick.dispose();
disposables.forEach(d => void d.dispose());
}
}

+ 18
- 2
src/webviews/apps/plus/patchDetails/components/gl-draft-details.ts Ver ficheiro

@ -345,7 +345,20 @@ export class GlDraftDetails extends GlTreeBase {
<div class="section section--sticky-actions">
<p class="button-container">
<span class="button-group button-group--single">
<gl-button full @click=${this.onApplyPatch}>Apply Cloud Patch</gl-button>
<gl-button full @click=${this.onApplyPatch}>Apply Patch</gl-button>
<gk-popover placement="top">
<gl-button
slot="trigger"
density="compact"
aria-label="Apply Patch Options..."
title="Apply Patch Options..."
><code-icon icon="chevron-down"></code-icon
></gl-button>
<gk-menu class="mine-menu" @select=${this.onSelectApplyOption}>
<gk-menu-item data-value="branch">Apply to new branch</gk-menu-item>
<!-- <gk-menu-item data-value="worktree">Apply to new worktree</gk-menu-item> -->
</gk-menu>
</gk-popover>
</span>
</p>
</div>
@ -577,7 +590,10 @@ export class GlDraftDetails extends GlTreeBase {
}
onSelectApplyOption(e: CustomEvent<{ target: MenuItem }>) {
if (this.canSubmit === false) return;
if (this.canSubmit === false) {
this.validityMessage = 'Please select changes to apply';
return;
}
const target = e.detail?.target;
if (target?.dataset?.value != null) {

+ 4
- 0
src/webviews/apps/plus/patchDetails/patchDetails.scss Ver ficheiro

@ -160,5 +160,9 @@ gl-patch-create {
&__group-fixed {
flex: none;
webview-pane::part(content) {
overflow: visible;
}
}
}

+ 5
- 1
src/webviews/apps/plus/patchDetails/patchDetails.ts Ver ficheiro

@ -264,7 +264,11 @@ export class PatchDetailsApp extends App> {
private onApplyPatch(e: ApplyPatchDetail) {
console.log('onApplyPatch', e);
if (e.selectedPatches == null || e.selectedPatches.length === 0) return;
this.sendCommand(ApplyPatchCommandType, { details: e.draft, selected: e.selectedPatches });
this.sendCommand(ApplyPatchCommandType, {
details: e.draft,
target: e.target ?? 'current',
selected: e.selectedPatches,
});
}
private onChangePatchBase(e: ChangePatchBaseDetail) {

+ 1
- 1
src/webviews/apps/shared/components/webview-pane.ts Ver ficheiro

@ -140,7 +140,7 @@ export class WebviewPane extends LitElement {
<slot name="actions"></slot>
<progress-indicator ?active="${this.loading}"></progress-indicator>
</header>
<div id="content" role="region" class="content scrollable">
<div id="content" role="region" part="content" class="content scrollable">
<slot></slot>
</div>
`;

Carregando…
Cancelar
Guardar