Skip to content

Commit cf87e61

Browse files
committed
Adds actions in home for paused git operations
1 parent fa25bae commit cf87e61

File tree

3 files changed

+109
-12
lines changed

3 files changed

+109
-12
lines changed

src/constants.commands.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,11 @@ type HomeWebviewCommands = `home.${
694694
| 'mergeIntoCurrent'
695695
| 'rebaseCurrentOnto'
696696
| 'startWork'
697-
| 'createCloudPatch'}`;
697+
| 'createCloudPatch'
698+
| 'skipPausedOperation'
699+
| 'continuePausedOperation'
700+
| 'abortPausedOperation'
701+
| 'openRebaseEditor'}`;
698702

699703
type GraphWebviewCommands = `graph.${
700704
| 'switchToEditorLayout'

src/webviews/apps/plus/home/components/merge-rebase-status.ts

Lines changed: 67 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import { css, html, LitElement, nothing } from 'lit';
22
import { customElement, property } from 'lit/decorators.js';
3+
import { when } from 'lit/directives/when.js';
34
import type { GitPausedOperationStatus } from '../../../../../git/models/pausedOperationStatus';
45
import { pausedOperationStatusStringsByType } from '../../../../../git/utils/pausedOperationStatus.utils';
6+
import { createCommandLink } from '../../../../../system/commands';
57
import { getReferenceLabel } from '../../../shared/git-utils';
8+
import '../../../shared/components/actions/action-item';
9+
import '../../../shared/components/actions/action-nav';
610
import '../../../shared/components/overlays/tooltip';
711

812
@customElement('gl-merge-rebase-status')
@@ -53,6 +57,30 @@ export class GlMergeConflictWarning extends LitElement {
5357
@property({ type: Object })
5458
pausedOpStatus?: GitPausedOperationStatus;
5559

60+
private get onSkipUrl() {
61+
return createCommandLink('gitlens.home.skipPausedOperation', {
62+
operation: this.pausedOpStatus,
63+
});
64+
}
65+
66+
private get onContinueUrl() {
67+
return createCommandLink('gitlens.home.continuePausedOperation', {
68+
operation: this.pausedOpStatus,
69+
});
70+
}
71+
72+
private get onAbortUrl() {
73+
return createCommandLink('gitlens.home.abortPausedOperation', {
74+
operation: this.pausedOpStatus,
75+
});
76+
}
77+
78+
private get onOpenEditorUrl() {
79+
return createCommandLink('gitlens.home.openRebaseEditor', {
80+
operation: this.pausedOpStatus,
81+
});
82+
}
83+
5684
override render() {
5785
if (this.pausedOpStatus == null) return nothing;
5886

@@ -68,14 +96,15 @@ export class GlMergeConflictWarning extends LitElement {
6896
if (pausedOpStatus.type !== 'rebase') {
6997
const strings = pausedOperationStatusStringsByType[pausedOpStatus.type];
7098
return html`<span class="label"
71-
>${this.conflicts ? strings.conflicts : strings.label}
72-
<code-icon
73-
icon="${pausedOpStatus.incoming.refType === 'branch' ? 'git-branch' : 'git-commit'}"
74-
class="icon"
75-
></code-icon>
76-
${getReferenceLabel(pausedOpStatus.incoming, { expand: false, icon: false })} ${strings.directionality}
77-
${getReferenceLabel(pausedOpStatus.current, { expand: false, icon: false })}</span
78-
>`;
99+
>${this.conflicts ? strings.conflicts : strings.label}
100+
<code-icon
101+
icon="${pausedOpStatus.incoming.refType === 'branch' ? 'git-branch' : 'git-commit'}"
102+
class="icon"
103+
></code-icon>
104+
${getReferenceLabel(pausedOpStatus.incoming, { expand: false, icon: false })}
105+
${strings.directionality}
106+
${getReferenceLabel(pausedOpStatus.current, { expand: false, icon: false })}</span
107+
>${this.renderActions()}`;
79108
}
80109

81110
const started = pausedOpStatus.steps.total > 0;
@@ -95,6 +124,35 @@ export class GlMergeConflictWarning extends LitElement {
95124
? html`<span class="steps"
96125
>(${pausedOpStatus.steps.current.number}/${pausedOpStatus.steps.total})</span
97126
>`
98-
: nothing}`;
127+
: nothing}${this.renderActions()}`;
128+
}
129+
130+
private renderActions() {
131+
if (this.pausedOpStatus == null) return nothing;
132+
133+
const status = this.pausedOpStatus.type;
134+
135+
return html`<action-nav>
136+
${when(
137+
status !== 'revert',
138+
() => html`
139+
<action-item label="Continue" icon="debug-continue" href=${this.onContinueUrl}></action-item>
140+
`,
141+
)}
142+
${when(
143+
status !== 'merge',
144+
() => html`<action-item label="Skip" icon="debug-step-over" href=${this.onSkipUrl}></action-item>`,
145+
)}
146+
<action-item label="Abort" href=${this.onAbortUrl} icon="circle-slash"></action-item>
147+
${when(
148+
status === 'rebase',
149+
() =>
150+
html`<action-item
151+
label="Open in Rebase Editor"
152+
href=${this.onOpenEditorUrl}
153+
icon="edit"
154+
></action-item>`,
155+
)}
156+
</action-nav>`;
99157
}
100158
}

src/webviews/home/homeWebview.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ConfigurationChangeEvent } from 'vscode';
2-
import { Disposable, workspace } from 'vscode';
2+
import { Disposable, Uri, workspace } from 'vscode';
33
import type { CreatePullRequestActionContext } from '../../api/gitlens';
44
import type { EnrichedAutolink } from '../../autolinks';
55
import { getAvatarUriFromGravatarEmail } from '../../avatars';
@@ -23,6 +23,7 @@ import type { GitBranch } from '../../git/models/branch';
2323
import { getAssociatedIssuesForBranch, getBranchTargetInfo } from '../../git/models/branch.utils';
2424
import type { GitFileChangeShape } from '../../git/models/file';
2525
import type { Issue } from '../../git/models/issue';
26+
import type { GitPausedOperationStatus } from '../../git/models/pausedOperationStatus';
2627
import type { PullRequest } from '../../git/models/pullRequest';
2728
import { getComparisonRefsForPullRequest } from '../../git/models/pullRequest';
2829
import { getReferenceFromBranch } from '../../git/models/reference.utils';
@@ -49,7 +50,7 @@ import type { Deferrable } from '../../system/function';
4950
import { debounce } from '../../system/function';
5051
import { filterMap } from '../../system/iterable';
5152
import { getSettledValue } from '../../system/promise';
52-
import { executeActionCommand, executeCommand, registerCommand } from '../../system/vscode/command';
53+
import { executeActionCommand, executeCommand, executeCoreCommand, registerCommand } from '../../system/vscode/command';
5354
import { configuration } from '../../system/vscode/configuration';
5455
import { getContext, onDidChangeContext } from '../../system/vscode/context';
5556
import { openUrl, openWorkspace } from '../../system/vscode/utils';
@@ -114,6 +115,9 @@ interface BranchRef {
114115
repoPath: string;
115116
branchId: string;
116117
}
118+
interface GitPausedOperationCommandArgs {
119+
operation: GitPausedOperationStatus;
120+
}
117121

118122
// type AutolinksInfo = Awaited<GetOverviewBranch['autolinks']>;
119123
type BranchMergeTargetStatusInfo = Awaited<GetOverviewBranch['mergeTarget']>;
@@ -309,6 +313,10 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
309313
registerCommand('gitlens.home.rebaseCurrentOnto', this.rebaseCurrentOnto, this),
310314
registerCommand('gitlens.home.startWork', this.startWork, this),
311315
registerCommand('gitlens.home.createCloudPatch', this.createCloudPatch, this),
316+
registerCommand('gitlens.home.skipPausedOperation', this.skipPausedOperation, this),
317+
registerCommand('gitlens.home.continuePausedOperation', this.continuePausedOperation, this),
318+
registerCommand('gitlens.home.abortPausedOperation', this.abortPausedOperation, this),
319+
registerCommand('gitlens.home.openRebaseEditor', this.openRebaseEditor, this),
312320
];
313321
}
314322

@@ -454,6 +462,33 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
454462
});
455463
}
456464

465+
private async abortPausedOperation(pausedOpArgs: GitPausedOperationCommandArgs) {
466+
await this.container.git.status(pausedOpArgs.operation.repoPath).abortPausedOperation?.();
467+
}
468+
469+
private async continuePausedOperation(pausedOpArgs: GitPausedOperationCommandArgs) {
470+
if (pausedOpArgs.operation.type === 'revert') return;
471+
await this.container.git.status(pausedOpArgs.operation.repoPath).continuePausedOperation?.();
472+
}
473+
474+
private async skipPausedOperation(pausedOpArgs: GitPausedOperationCommandArgs) {
475+
if (pausedOpArgs.operation.type === 'merge') return;
476+
477+
await this.container.git.status(pausedOpArgs.operation.repoPath).continuePausedOperation?.({ skip: true });
478+
}
479+
480+
private async openRebaseEditor(pausedOpArgs: GitPausedOperationCommandArgs) {
481+
if (pausedOpArgs.operation.type !== 'rebase') return;
482+
483+
const repo = this._repositoryBranches.get(pausedOpArgs.operation.repoPath)?.repo;
484+
if (repo == null) return;
485+
486+
const rebaseTodoUri = Uri.joinPath(repo.uri, '.git', 'rebase-merge', 'git-rebase-todo');
487+
await executeCoreCommand('vscode.openWith', rebaseTodoUri, 'gitlens.rebase', {
488+
preview: false,
489+
});
490+
}
491+
457492
private async createCloudPatch(refs: BranchRef) {
458493
const status = await this.container.git.status(refs.repoPath).getStatus();
459494
if (status == null) return;

0 commit comments

Comments
 (0)