Skip to content

Commit 3a14aa0

Browse files
Implements push and adds checkout backup for delete
1 parent ff0cba7 commit 3a14aa0

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
@@ -1165,10 +1165,15 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
11651165
});
11661166
}
11671167

1168-
private deleteBranchOrWorktree(ref: BranchRef) {
1168+
private async deleteBranchOrWorktree(ref: BranchRef, mergeTarget?: BranchRef) {
11691169
const repo = this._repositoryBranches.get(ref.repoPath);
11701170
const branch = repo?.branches.find(b => b.id === ref.branchId);
11711171
if (branch == null) return;
1172+
if (branch.current) {
1173+
if (mergeTarget != null) {
1174+
await this.container.git.checkout(ref.repoPath, mergeTarget.branchName);
1175+
}
1176+
}
11721177

11731178
void executeGitCommand({
11741179
command: 'branch',
@@ -1180,8 +1185,16 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
11801185
});
11811186
}
11821187

1183-
private pushBranch(_ref: BranchRef) {
1184-
// TODO
1188+
private pushBranch(ref: BranchRef) {
1189+
void this.container.git.push(ref.repoPath, {
1190+
reference: {
1191+
name: ref.branchName,
1192+
ref: ref.branchId,
1193+
refType: 'branch',
1194+
remote: false,
1195+
repoPath: ref.repoPath,
1196+
},
1197+
});
11851198
}
11861199

11871200
private mergeTargetCompare(ref: BranchAndTargetRefs) {

0 commit comments

Comments
 (0)