Skip to content

Commit 78ee7ea

Browse files
Implements push and adds checkout backup for delete
1 parent dbd0053 commit 78ee7ea

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { css, html, LitElement, nothing } from 'lit';
22
import { customElement, property, state } from 'lit/decorators.js';
3+
import { merge } from '../../../../../git/actions/repository';
34
import { createCommandLink } from '../../../../../system/commands';
45
import { pluralize } from '../../../../../system/string';
56
import type { BranchAndTargetRefs, BranchRef, GetOverviewBranch } from '../../../../home/protocol';
@@ -287,6 +288,11 @@ export class GlMergeTargetStatus extends LitElement {
287288

288289
if (this.mergedStatus?.merged) {
289290
if (this.mergedStatus.localBranchOnly) {
291+
const mergeTargetRef = {
292+
repoPath: this.branch.repoPath,
293+
branchId: this.mergedStatus.localBranchOnly.id!,
294+
branchName: this.mergedStatus.localBranchOnly.name,
295+
};
290296
return html`<div class="header">
291297
<span class="header__title"
292298
><code-icon icon="git-merge"></code-icon> Branch
@@ -304,17 +310,19 @@ export class GlMergeTargetStatus extends LitElement {
304310
<div class="button-container">
305311
<gl-button
306312
full
307-
href="${createCommandLink('gitlens.home.pushBranch', {
308-
repoPath: this.branch.repoPath,
309-
branchId: this.mergedStatus.localBranchOnly.id!,
310-
branchName: this.mergedStatus.localBranchOnly.name,
311-
} satisfies BranchRef)}"
313+
href="${createCommandLink(
314+
'gitlens.home.pushBranch',
315+
mergeTargetRef satisfies BranchRef,
316+
)}"
312317
>Push ${renderBranchName(this.mergedStatus.localBranchOnly.name)}</gl-button
313318
>
314319
<gl-button
315320
full
316321
appearance="secondary"
317-
href="${createCommandLink('gitlens.home.deleteBranchOrWorktree', this.branchRef)}"
322+
href="${createCommandLink('gitlens.home.deleteBranchOrWorktree', [
323+
this.branchRef,
324+
mergeTargetRef,
325+
])}"
318326
>Delete ${this.branch.worktree ? 'Worktree' : 'Branch'}
319327
${renderBranchName(this.branch.name, this.branch.worktree != null)}</gl-button
320328
>

src/webviews/home/homeWebview.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,10 +1187,15 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
11871187
});
11881188
}
11891189

1190-
private deleteBranchOrWorktree(ref: BranchRef) {
1190+
private async deleteBranchOrWorktree(ref: BranchRef, mergeTarget?: BranchRef) {
11911191
const repo = this._repositoryBranches.get(ref.repoPath);
11921192
const branch = repo?.branches.find(b => b.id === ref.branchId);
11931193
if (branch == null) return;
1194+
if (branch.current) {
1195+
if (mergeTarget != null) {
1196+
await this.container.git.checkout(ref.repoPath, mergeTarget.branchName);
1197+
}
1198+
}
11941199

11951200
void executeGitCommand({
11961201
command: 'branch',
@@ -1202,8 +1207,16 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
12021207
});
12031208
}
12041209

1205-
private pushBranch(_ref: BranchRef) {
1206-
// TODO
1210+
private pushBranch(ref: BranchRef) {
1211+
void this.container.git.push(ref.repoPath, {
1212+
reference: {
1213+
name: ref.branchName,
1214+
ref: ref.branchId,
1215+
refType: 'branch',
1216+
remote: false,
1217+
repoPath: ref.repoPath,
1218+
},
1219+
});
12071220
}
12081221

12091222
private mergeTargetCompare(ref: BranchAndTargetRefs) {

0 commit comments

Comments
 (0)