Skip to content

Commit f23ecc5

Browse files
Passes merge target more consistently and fixes checkout
1 parent c92c635 commit f23ecc5

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

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

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -285,14 +285,25 @@ export class GlMergeTargetStatus extends LitElement {
285285
private renderContent() {
286286
const target = renderBranchName(this.target?.name);
287287

288+
const mergeTargetRef =
289+
this.mergedStatus?.merged && this.mergedStatus.localBranchOnly
290+
? {
291+
repoPath: this.branch.repoPath,
292+
branchId: this.mergedStatus.localBranchOnly.id!,
293+
branchName: this.mergedStatus.localBranchOnly.name,
294+
branchUpstreamName: this.mergedStatus.localBranchOnly.upstream?.name,
295+
}
296+
: this.target
297+
? {
298+
repoPath: this.target.repoPath,
299+
branchId: this.target.id,
300+
branchName: this.target.name,
301+
branchUpstreamName: undefined,
302+
}
303+
: undefined;
304+
288305
if (this.mergedStatus?.merged) {
289306
if (this.mergedStatus.localBranchOnly) {
290-
const mergeTargetRef = {
291-
repoPath: this.branch.repoPath,
292-
branchId: this.mergedStatus.localBranchOnly.id!,
293-
branchName: this.mergedStatus.localBranchOnly.name,
294-
branchUpstreamName: this.mergedStatus.localBranchOnly.upstream?.name,
295-
};
296307
return html`<div class="header">
297308
<span class="header__title"
298309
><code-icon icon="git-merge"></code-icon> Branch
@@ -312,7 +323,7 @@ export class GlMergeTargetStatus extends LitElement {
312323
full
313324
href="${createCommandLink(
314325
'gitlens.home.pushBranch',
315-
mergeTargetRef satisfies BranchRef,
326+
mergeTargetRef! satisfies BranchRef,
316327
)}"
317328
>Push ${renderBranchName(this.mergedStatus.localBranchOnly.name)}</gl-button
318329
>
@@ -350,7 +361,10 @@ export class GlMergeTargetStatus extends LitElement {
350361
<div class="button-container">
351362
<gl-button
352363
full
353-
href="${createCommandLink('gitlens.home.deleteBranchOrWorktree', this.branchRef)}"
364+
href="${createCommandLink('gitlens.home.deleteBranchOrWorktree', [
365+
this.branchRef,
366+
mergeTargetRef,
367+
])}"
354368
>Delete
355369
${this.branch.worktree != null && !this.branch.worktree.isDefault ? 'Worktree' : 'Branch'}
356370
${renderBranchName(this.branch.name, this.branch.worktree != null)}</gl-button

src/webviews/home/homeWebview.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { getBranchTargetInfo } from '../../git/utils/-webview/branch.utils';
3636
import { getReferenceFromBranch } from '../../git/utils/-webview/reference.utils';
3737
import { sortBranches } from '../../git/utils/-webview/sorting';
3838
import { getOpenedWorktreesByBranch, groupWorktreesByBranch } from '../../git/utils/-webview/worktree.utils';
39+
import { getBranchNameWithoutRemote } from '../../git/utils/branch.utils';
3940
import { getComparisonRefsForPullRequest } from '../../git/utils/pullRequest.utils';
4041
import { createRevisionRange } from '../../git/utils/revision.utils';
4142
import { showPatchesView } from '../../plus/drafts/actions';
@@ -1191,9 +1192,10 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
11911192
const repo = this._repositoryBranches.get(ref.repoPath);
11921193
const branch = repo?.branches.find(b => b.id === ref.branchId);
11931194
if (branch == null) return;
1194-
if (branch.current) {
1195+
if (branch.current && mergeTarget != null) {
11951196
if (mergeTarget != null) {
1196-
await this.container.git.checkout(ref.repoPath, mergeTarget.branchName);
1197+
const mergeTargetLocalBranch = getBranchNameWithoutRemote(mergeTarget.branchName);
1198+
await this.container.git.checkout(ref.repoPath, mergeTargetLocalBranch);
11971199
}
11981200
}
11991201

0 commit comments

Comments
 (0)