Skip to content

Commit 0be0a56

Browse files
committed
Fixes #201 checks tracking vs has remotes
1 parent 8b859fa commit 0be0a56

File tree

10 files changed

+51
-29
lines changed

10 files changed

+51
-29
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [Unreleased]
8+
### Fixed
9+
- Fixes [#201](https://github.com/eamodio/vscode-gitlens/issues/201) - "Open in Remote" commands should check for branch upstream tracking
10+
711
## [6.1.0] - 2017-11-13
812
### Added
913
- Adds support for nested repositories and submodules -- closes [#198](https://github.com/eamodio/vscode-gitlens/issues/198)

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,23 +1496,23 @@
14961496
},
14971497
{
14981498
"command": "gitlens.openBranchesInRemote",
1499-
"when": "gitlens:activeHasRemotes"
1499+
"when": "gitlens:activeHasRemote"
15001500
},
15011501
{
15021502
"command": "gitlens.openBranchInRemote",
1503-
"when": "gitlens:activeHasRemotes"
1503+
"when": "gitlens:activeHasRemote"
15041504
},
15051505
{
15061506
"command": "gitlens.openCommitInRemote",
1507-
"when": "gitlens:activeIsBlameable && gitlens:activeHasRemotes"
1507+
"when": "gitlens:activeIsBlameable && gitlens:activeHasRemote"
15081508
},
15091509
{
15101510
"command": "gitlens.openFileInRemote",
1511-
"when": "gitlens:activeIsTracked && gitlens:activeHasRemotes"
1511+
"when": "gitlens:activeIsTracked && gitlens:activeHasRemote"
15121512
},
15131513
{
15141514
"command": "gitlens.openRepoInRemote",
1515-
"when": "gitlens:activeHasRemotes"
1515+
"when": "gitlens:activeHasRemote"
15161516
},
15171517
{
15181518
"command": "gitlens.stashApply",
@@ -1638,7 +1638,7 @@
16381638
"editor/context": [
16391639
{
16401640
"command": "gitlens.openFileInRemote",
1641-
"when": "editorTextFocus && gitlens:activeHasRemotes && config.gitlens.advanced.menus.editorContext.remote",
1641+
"when": "editorTextFocus && gitlens:activeHasRemote && config.gitlens.advanced.menus.editorContext.remote",
16421642
"group": "navigation@100"
16431643
},
16441644
{
@@ -1706,12 +1706,12 @@
17061706
},
17071707
{
17081708
"command": "gitlens.openFileInRemote",
1709-
"when": "gitlens:enabled && gitlens:activeHasRemotes && config.gitlens.advanced.menus.editorTitle.remote",
1709+
"when": "gitlens:enabled && gitlens:activeHasRemote && config.gitlens.advanced.menus.editorTitle.remote",
17101710
"group": "1_gitlens"
17111711
},
17121712
{
17131713
"command": "gitlens.openRepoInRemote",
1714-
"when": "gitlens:enabled && gitlens:activeHasRemotes && config.gitlens.advanced.menus.editorTitle.remote",
1714+
"when": "gitlens:enabled && gitlens:activeHasRemote && config.gitlens.advanced.menus.editorTitle.remote",
17151715
"group": "1_gitlens"
17161716
},
17171717
{
@@ -1743,7 +1743,7 @@
17431743
"editor/title/context": [
17441744
{
17451745
"command": "gitlens.openFileInRemote",
1746-
"when": "gitlens:enabled && gitlens:hasRemotes && config.gitlens.advanced.menus.editorTitleContext.remote",
1746+
"when": "gitlens:enabled && gitlens:activeHasRemote && config.gitlens.advanced.menus.editorTitleContext.remote",
17471747
"group": "1_gitlens"
17481748
},
17491749
{

src/annotations/annotations.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export class Annotations {
4848
return '#793738';
4949
}
5050

51-
private static getHoverCommandBar(commit: GitCommit, hasRemotes: boolean, annotationType?: FileAnnotationType) {
51+
private static getHoverCommandBar(commit: GitCommit, hasRemote: boolean, annotationType?: FileAnnotationType) {
5252
let commandBar = `[\`${GlyphChars.DoubleArrowLeft}\`](${DiffWithCommand.getMarkdownCommandArgs(commit)} "Open Changes") `;
5353

5454
if (commit.previousSha !== undefined) {
@@ -62,7 +62,7 @@ export class Annotations {
6262
commandBar += `[\`${GlyphChars.SquareWithTopShadow}\`](${OpenFileRevisionCommand.getMarkdownCommandArgs(uri, annotationType || FileAnnotationType.Gutter, line)} "Blame Previous Revision") `;
6363
}
6464

65-
if (hasRemotes) {
65+
if (hasRemote) {
6666
commandBar += `[\`${GlyphChars.ArrowUpRight}\`](${OpenCommitInRemoteCommand.getMarkdownCommandArgs(commit.sha)} "Open in Remote") `;
6767
}
6868

@@ -71,7 +71,7 @@ export class Annotations {
7171
return commandBar;
7272
}
7373

74-
static getHoverMessage(commit: GitCommit, dateFormat: string | null, hasRemotes: boolean, annotationType?: FileAnnotationType): MarkdownString {
74+
static getHoverMessage(commit: GitCommit, dateFormat: string | null, hasRemote: boolean, annotationType?: FileAnnotationType): MarkdownString {
7575
if (dateFormat === null) {
7676
dateFormat = 'MMMM Do, YYYY h:MMa';
7777
}
@@ -80,7 +80,7 @@ export class Annotations {
8080
let commandBar = '';
8181
let showCommitDetailsCommand = '';
8282
if (!commit.isUncommitted) {
83-
commandBar = `\n\n${this.getHoverCommandBar(commit, hasRemotes, annotationType)}`;
83+
commandBar = `\n\n${this.getHoverCommandBar(commit, hasRemote, annotationType)}`;
8484
showCommitDetailsCommand = `[\`${commit.shortSha}\`](${ShowQuickCommitDetailsCommand.getMarkdownCommandArgs(commit.sha)} "Show Commit Details")`;
8585

8686
message = commit.message
@@ -129,8 +129,8 @@ export class Annotations {
129129
} as DecorationOptions;
130130
}
131131

132-
static detailsHover(commit: GitCommit, dateFormat: string | null, hasRemotes: boolean, annotationType?: FileAnnotationType): DecorationOptions {
133-
const message = this.getHoverMessage(commit, dateFormat, hasRemotes, annotationType);
132+
static detailsHover(commit: GitCommit, dateFormat: string | null, hasRemote: boolean, annotationType?: FileAnnotationType): DecorationOptions {
133+
const message = this.getHoverMessage(commit, dateFormat, hasRemote, annotationType);
134134
return {
135135
hoverMessage: message
136136
} as DecorationOptions;

src/annotations/blameAnnotationProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export abstract class BlameAnnotationProviderBase extends AnnotationProviderBase
103103
}
104104
}
105105

106-
const message = Annotations.getHoverMessage(logCommit || commit, this._config.defaultDateFormat, await this.git.hasRemotes(commit.repoPath), this._config.blame.file.annotationType);
106+
const message = Annotations.getHoverMessage(logCommit || commit, this._config.defaultDateFormat, await this.git.hasRemote(commit.repoPath), this._config.blame.file.annotationType);
107107
return new Hover(message, document.validateRange(new Range(position.line, 0, position.line, endOfLineIndex)));
108108
}
109109

src/annotations/recentChangesAnnotationProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export class RecentChangesAnnotationProvider extends AnnotationProviderBase {
4848

4949
if (cfg.hover.details) {
5050
this._decorations.push({
51-
hoverMessage: Annotations.getHoverMessage(commit, dateFormat, await this.git.hasRemotes(commit.repoPath), this._config.blame.file.annotationType),
51+
hoverMessage: Annotations.getHoverMessage(commit, dateFormat, await this.git.hasRemote(commit.repoPath), this._config.blame.file.annotationType),
5252
range: range
5353
} as DecorationOptions);
5454
}

src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export enum CommandContext {
3535
GitExplorerView = 'gitlens:gitExplorer:view',
3636
HasRemotes = 'gitlens:hasRemotes',
3737
HasRepository = 'gitlens:hasRepository',
38-
ActiveHasRemotes = 'gitlens:activeHasRemotes',
38+
ActiveHasRemote = 'gitlens:activeHasRemote',
3939
ActiveIsBlameable = 'gitlens:activeIsBlameable',
4040
ActiveFileIsTracked = 'gitlens:activeIsTracked',
4141
Key = 'gitlens:key'

src/currentLineController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ export class CurrentLineController extends Disposable {
427427
}
428428
}
429429

430-
const message = Annotations.getHoverMessage(logCommit || commit, this._config.defaultDateFormat, await this.git.hasRemotes(commit.repoPath), this._config.blame.file.annotationType);
430+
const message = Annotations.getHoverMessage(logCommit || commit, this._config.defaultDateFormat, await this.git.hasRemote(commit.repoPath), this._config.blame.file.annotationType);
431431
return new Hover(message, range);
432432
}
433433

src/git/gitContextTracker.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,11 @@ export class GitContextTracker extends Disposable {
191191
private async updateRemotes() {
192192
let hasRemotes = false;
193193
if (this._context.repo !== undefined) {
194-
hasRemotes = await this._context.repo.hasRemotes();
195-
setCommandContext(CommandContext.ActiveHasRemotes, hasRemotes);
196-
}
197-
else {
198-
setCommandContext(CommandContext.ActiveHasRemotes, false);
194+
hasRemotes = await this._context.repo.hasRemote();
199195
}
200196

197+
setCommandContext(CommandContext.ActiveHasRemote, hasRemotes);
198+
201199
if (!hasRemotes) {
202200
const repositories = await this.git.getRepositories();
203201
for (const repo of repositories) {

src/git/models/repository.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,15 @@ export class Repository extends Disposable {
6565
readonly normalizedPath: string;
6666
readonly storage: Map<string, any> = new Map();
6767

68+
private _branch: Promise<GitBranch | undefined> | undefined;
6869
private readonly _disposable: Disposable;
6970
private _fireChangeDebounced: ((e: RepositoryChangeEvent) => void) | undefined = undefined;
7071
private _fireFileSystemChangeDebounced: ((e: RepositoryFileSystemChangeEvent) => void) | undefined = undefined;
7172
private _fsWatchCounter = 0;
7273
private _fsWatcherDisposable: Disposable | undefined;
7374
private _pendingChanges: { repo?: RepositoryChangeEvent, fs?: RepositoryFileSystemChangeEvent } = { };
7475
private _providerMap: RemoteProviderMap | undefined;
75-
private _remotes: GitRemote[] | undefined;
76+
private _remotes: Promise<GitRemote[]> | undefined;
7677
private _suspended: boolean;
7778

7879
constructor(
@@ -148,6 +149,8 @@ export class Repository extends Disposable {
148149
return;
149150
}
150151

152+
this._branch = undefined;
153+
151154
if (uri !== undefined && uri.path.endsWith('refs/remotes')) {
152155
this._remotes = undefined;
153156
this.fireChange(RepositoryChange.Remotes);
@@ -227,8 +230,11 @@ export class Repository extends Disposable {
227230
return this.folder === workspace.getWorkspaceFolder(uri);
228231
}
229232

230-
async getBranch(): Promise<GitBranch | undefined> {
231-
return this.git.getBranch(this.path);
233+
getBranch(): Promise<GitBranch | undefined> {
234+
if (this._branch === undefined) {
235+
this._branch = this.git.getBranch(this.path);
236+
}
237+
return this._branch;
232238
}
233239

234240
async getBranches(): Promise<GitBranch[]> {
@@ -239,14 +245,14 @@ export class Repository extends Disposable {
239245
return this.git.getChangedFilesCount(this.path, sha);
240246
}
241247

242-
async getRemotes(): Promise<GitRemote[]> {
248+
getRemotes(): Promise<GitRemote[]> {
243249
if (this._remotes === undefined) {
244250
if (this._providerMap === undefined) {
245251
const remotesCfg = configuration.get<IRemotesConfig[] | null | undefined>(configuration.name('remotes').value, this.folder.uri);
246252
this._providerMap = RemoteProviderFactory.createMap(remotesCfg);
247253
}
248254

249-
this._remotes = await this.git.getRemotesCore(this.path, this._providerMap);
255+
this._remotes = this.git.getRemotesCore(this.path, this._providerMap);
250256
}
251257

252258
return this._remotes;
@@ -260,6 +266,11 @@ export class Repository extends Disposable {
260266
return this.git.getStatusForRepo(this.path);
261267
}
262268

269+
async hasRemote(): Promise<boolean> {
270+
const branch = await this.getBranch();
271+
return branch !== undefined && branch.tracking !== undefined;
272+
}
273+
263274
async hasRemotes(): Promise<boolean> {
264275
const remotes = await this.getRemotes();
265276
return remotes !== undefined && remotes.length > 0;

src/gitService.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,15 @@ export class GitService extends Disposable {
992992
}
993993
}
994994

995+
async hasRemote(repoPath: string | undefined): Promise<boolean> {
996+
if (repoPath === undefined) return false;
997+
998+
const repository = await this.getRepository(repoPath);
999+
if (repository === undefined) return false;
1000+
1001+
return repository.hasRemote();
1002+
}
1003+
9951004
async hasRemotes(repoPath: string | undefined): Promise<boolean> {
9961005
if (repoPath === undefined) return false;
9971006

0 commit comments

Comments
 (0)