Skip to content

Commit c4005d9

Browse files
committed
Fixes #2847 missed local branches with upstreams
1 parent 443e868 commit c4005d9

File tree

6 files changed

+30
-34
lines changed

6 files changed

+30
-34
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1313
### Fixed
1414

1515
- Fixes [#2841](https://github.com/gitkraken/vscode-gitlens/issues/2841) - Error when trying to browse commits
16+
- Fixes [#2847](https://github.com/gitkraken/vscode-gitlens/issues/2847) - 14.2.0 Breaks "pull" action works fine in 14.1.1
1617

1718
## [14.2.0] - 2023-08-04
1819

src/commands/copyDeepLink.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { StoredNamedRef } from '../constants';
33
import { Commands } from '../constants';
44
import type { Container } from '../container';
55
import { GitUri } from '../git/gitUri';
6-
import { splitBranchNameAndRemote } from '../git/models/branch';
6+
import { getBranchNameAndRemote } from '../git/models/branch';
77
import type { GitReference } from '../git/models/reference';
88
import { showGenericErrorMessage } from '../messages';
99
import { showRemotePicker } from '../quickpicks/remotePicker';
@@ -91,11 +91,8 @@ export class CopyDeepLinkCommand extends ActiveEditorCommand {
9191
if (args.refOrRepoPath?.refType === 'branch') {
9292
// If the branch is remote, or has an upstream, pre-select the remote
9393
if (args.refOrRepoPath.remote || args.refOrRepoPath.upstream?.name != null) {
94-
const [branchName, remoteName] = splitBranchNameAndRemote(
95-
args.refOrRepoPath.remote ? args.refOrRepoPath.name : args.refOrRepoPath.upstream!.name,
96-
);
97-
98-
if (branchName != null) {
94+
const [branchName, remoteName] = getBranchNameAndRemote(args.refOrRepoPath);
95+
if (branchName != null && remoteName != null) {
9996
args.remote = remoteName;
10097
args.prePickRemote = true;
10198
}

src/env/node/git/localGitProvider.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import type { GitBlame, GitBlameAuthor, GitBlameLine, GitBlameLines } from '../.
5353
import type { BranchSortOptions } from '../../../git/models/branch';
5454
import {
5555
getBranchId,
56+
getBranchNameAndRemote,
5657
getBranchNameWithoutRemote,
5758
getRemoteNameFromBranchName,
5859
GitBranch,
@@ -92,7 +93,6 @@ import {
9293
isUncommitted,
9394
isUncommittedStaged,
9495
shortenRevision,
95-
splitRefNameAndRemote,
9696
} from '../../../git/models/reference';
9797
import type { GitReflog } from '../../../git/models/reflog';
9898
import { getRemoteIconUri, getVisibilityCacheKey, GitRemote } from '../../../git/models/remote';
@@ -1165,13 +1165,12 @@ export class LocalGitProvider implements GitProvider, Disposable {
11651165
const { branch, ...opts } = options ?? {};
11661166
try {
11671167
if (isBranchReference(branch)) {
1168-
if (!branch?.remote && branch?.upstream == null) return undefined;
1169-
1170-
const [branchName, remoteName] = splitRefNameAndRemote(branch);
1168+
const [branchName, remoteName] = getBranchNameAndRemote(branch);
1169+
if (remoteName == null) return undefined;
11711170

11721171
await this.git.fetch(repoPath, {
11731172
branch: branchName,
1174-
remote: remoteName!,
1173+
remote: remoteName,
11751174
upstream: getBranchTrackingWithoutRemote(branch)!,
11761175
pull: options?.pull,
11771176
});
@@ -1202,7 +1201,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
12021201
if (branch == null) return undefined;
12031202
}
12041203

1205-
const [branchName, remoteName] = splitRefNameAndRemote(branch);
1204+
const [branchName, remoteName] = getBranchNameAndRemote(branch);
12061205
if (options?.publish == null && remoteName == null && branch.upstream == null) {
12071206
return undefined;
12081207
}
@@ -1239,7 +1238,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
12391238
if (branch == null) return undefined;
12401239
}
12411240

1242-
const [branchName, remoteName] = splitRefNameAndRemote(branch);
1241+
const [branchName, remoteName] = getBranchNameAndRemote(branch);
12431242
if (remoteName == null && branch.upstream == null) return undefined;
12441243

12451244
try {

src/git/models/branch.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,24 @@ export function getRemoteNameSlashIndex(name: string): number {
224224
return name.startsWith('remotes/') ? name.indexOf('/', 8) : name.indexOf('/');
225225
}
226226

227+
export function getBranchNameAndRemote(ref: GitBranchReference): [name: string, remote: string | undefined] {
228+
if (ref.remote) {
229+
const index = getRemoteNameSlashIndex(ref.name);
230+
if (index === -1) return [ref.name, undefined];
231+
232+
return [ref.name.substring(index + 1), ref.name.substring(0, index)];
233+
}
234+
235+
if (ref.upstream?.name != null) {
236+
const index = getRemoteNameSlashIndex(ref.upstream.name);
237+
if (index === -1) return [ref.name, undefined];
238+
239+
return [ref.name, ref.upstream.name.substring(0, index)];
240+
}
241+
242+
return [ref.name, undefined];
243+
}
244+
227245
export function getBranchNameWithoutRemote(name: string): string {
228246
return name.substring(getRemoteNameSlashIndex(name) + 1);
229247
}
@@ -246,13 +264,6 @@ export function isOfBranchRefType(branch: GitReference | undefined) {
246264
return branch?.refType === 'branch';
247265
}
248266

249-
export function splitBranchNameAndRemote(name: string): [name: string, remote: string | undefined] {
250-
const index = getRemoteNameSlashIndex(name);
251-
if (index === -1) return [name, undefined];
252-
253-
return [name.substring(index + 1), name.substring(0, index)];
254-
}
255-
256267
export function sortBranches(branches: GitBranch[], options?: BranchSortOptions) {
257268
options = { current: true, orderBy: configuration.get('sortBranchesBy'), ...options };
258269

src/git/models/reference.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import { GlyphChars } from '../../constants';
22
import { configuration } from '../../system/configuration';
3-
import {
4-
getBranchNameWithoutRemote,
5-
getRemoteNameFromBranchName,
6-
getRemoteNameSlashIndex,
7-
splitBranchNameAndRemote,
8-
} from './branch';
3+
import { getBranchNameWithoutRemote, getRemoteNameFromBranchName, getRemoteNameSlashIndex } from './branch';
94
import { deletedOrMissing, uncommitted, uncommittedStaged } from './constants';
105

116
const rangeRegex = /^(\S*?)(\.\.\.?)(\S*)\s*$/;
@@ -399,10 +394,3 @@ export function getReferenceLabel(
399394
return `${refs.length} ${isStashReference(refs[0]) ? 'stashes' : 'commits'}${expanded}`;
400395
}
401396
}
402-
403-
export function splitRefNameAndRemote(ref: GitReference): [name: string, remote: string | undefined] {
404-
if (ref.refType === 'branch') {
405-
return ref.remote ? splitBranchNameAndRemote(ref.name) : [ref.name, undefined];
406-
}
407-
return [ref.name, undefined];
408-
}

src/git/models/repository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ export class Repository implements Disposable {
574574
remote?: string;
575575
}) {
576576
try {
577-
if (configuration.get('experimental.nativeGit') === true || options?.branch != null) {
577+
if (options?.branch != null || configuration.get('experimental.nativeGit') === true) {
578578
await this.container.git.fetch(this.path, options);
579579
} else {
580580
void (await executeCoreGitCommand('git.fetch', this.path));

0 commit comments

Comments
 (0)