Browse Source

Fixes #201 checks tracking vs has remotes

main
Eric Amodio 7 years ago
parent
commit
0be0a56577
10 changed files with 51 additions and 29 deletions
  1. +4
    -0
      CHANGELOG.md
  2. +9
    -9
      package.json
  3. +6
    -6
      src/annotations/annotations.ts
  4. +1
    -1
      src/annotations/blameAnnotationProvider.ts
  5. +1
    -1
      src/annotations/recentChangesAnnotationProvider.ts
  6. +1
    -1
      src/constants.ts
  7. +1
    -1
      src/currentLineController.ts
  8. +3
    -5
      src/git/gitContextTracker.ts
  9. +16
    -5
      src/git/models/repository.ts
  10. +9
    -0
      src/gitService.ts

+ 4
- 0
CHANGELOG.md View File

@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
### Fixed
- Fixes [#201](https://github.com/eamodio/vscode-gitlens/issues/201) - "Open in Remote" commands should check for branch upstream tracking
## [6.1.0] - 2017-11-13 ## [6.1.0] - 2017-11-13
### Added ### Added
- Adds support for nested repositories and submodules -- closes [#198](https://github.com/eamodio/vscode-gitlens/issues/198) - Adds support for nested repositories and submodules -- closes [#198](https://github.com/eamodio/vscode-gitlens/issues/198)

+ 9
- 9
package.json View File

@ -1496,23 +1496,23 @@
}, },
{ {
"command": "gitlens.openBranchesInRemote", "command": "gitlens.openBranchesInRemote",
"when": "gitlens:activeHasRemotes"
"when": "gitlens:activeHasRemote"
}, },
{ {
"command": "gitlens.openBranchInRemote", "command": "gitlens.openBranchInRemote",
"when": "gitlens:activeHasRemotes"
"when": "gitlens:activeHasRemote"
}, },
{ {
"command": "gitlens.openCommitInRemote", "command": "gitlens.openCommitInRemote",
"when": "gitlens:activeIsBlameable && gitlens:activeHasRemotes"
"when": "gitlens:activeIsBlameable && gitlens:activeHasRemote"
}, },
{ {
"command": "gitlens.openFileInRemote", "command": "gitlens.openFileInRemote",
"when": "gitlens:activeIsTracked && gitlens:activeHasRemotes"
"when": "gitlens:activeIsTracked && gitlens:activeHasRemote"
}, },
{ {
"command": "gitlens.openRepoInRemote", "command": "gitlens.openRepoInRemote",
"when": "gitlens:activeHasRemotes"
"when": "gitlens:activeHasRemote"
}, },
{ {
"command": "gitlens.stashApply", "command": "gitlens.stashApply",
@ -1638,7 +1638,7 @@
"editor/context": [ "editor/context": [
{ {
"command": "gitlens.openFileInRemote", "command": "gitlens.openFileInRemote",
"when": "editorTextFocus && gitlens:activeHasRemotes && config.gitlens.advanced.menus.editorContext.remote",
"when": "editorTextFocus && gitlens:activeHasRemote && config.gitlens.advanced.menus.editorContext.remote",
"group": "navigation@100" "group": "navigation@100"
}, },
{ {
@ -1706,12 +1706,12 @@
}, },
{ {
"command": "gitlens.openFileInRemote", "command": "gitlens.openFileInRemote",
"when": "gitlens:enabled && gitlens:activeHasRemotes && config.gitlens.advanced.menus.editorTitle.remote",
"when": "gitlens:enabled && gitlens:activeHasRemote && config.gitlens.advanced.menus.editorTitle.remote",
"group": "1_gitlens" "group": "1_gitlens"
}, },
{ {
"command": "gitlens.openRepoInRemote", "command": "gitlens.openRepoInRemote",
"when": "gitlens:enabled && gitlens:activeHasRemotes && config.gitlens.advanced.menus.editorTitle.remote",
"when": "gitlens:enabled && gitlens:activeHasRemote && config.gitlens.advanced.menus.editorTitle.remote",
"group": "1_gitlens" "group": "1_gitlens"
}, },
{ {
@ -1743,7 +1743,7 @@
"editor/title/context": [ "editor/title/context": [
{ {
"command": "gitlens.openFileInRemote", "command": "gitlens.openFileInRemote",
"when": "gitlens:enabled && gitlens:hasRemotes && config.gitlens.advanced.menus.editorTitleContext.remote",
"when": "gitlens:enabled && gitlens:activeHasRemote && config.gitlens.advanced.menus.editorTitleContext.remote",
"group": "1_gitlens" "group": "1_gitlens"
}, },
{ {

+ 6
- 6
src/annotations/annotations.ts View File

@ -48,7 +48,7 @@ export class Annotations {
return '#793738'; return '#793738';
} }
private static getHoverCommandBar(commit: GitCommit, hasRemotes: boolean, annotationType?: FileAnnotationType) {
private static getHoverCommandBar(commit: GitCommit, hasRemote: boolean, annotationType?: FileAnnotationType) {
let commandBar = `[\`${GlyphChars.DoubleArrowLeft}\`](${DiffWithCommand.getMarkdownCommandArgs(commit)} "Open Changes") `; let commandBar = `[\`${GlyphChars.DoubleArrowLeft}\`](${DiffWithCommand.getMarkdownCommandArgs(commit)} "Open Changes") `;
if (commit.previousSha !== undefined) { if (commit.previousSha !== undefined) {
@ -62,7 +62,7 @@ export class Annotations {
commandBar += `[\`${GlyphChars.SquareWithTopShadow}\`](${OpenFileRevisionCommand.getMarkdownCommandArgs(uri, annotationType || FileAnnotationType.Gutter, line)} "Blame Previous Revision") `; commandBar += `[\`${GlyphChars.SquareWithTopShadow}\`](${OpenFileRevisionCommand.getMarkdownCommandArgs(uri, annotationType || FileAnnotationType.Gutter, line)} "Blame Previous Revision") `;
} }
if (hasRemotes) {
if (hasRemote) {
commandBar += `[\`${GlyphChars.ArrowUpRight}\`](${OpenCommitInRemoteCommand.getMarkdownCommandArgs(commit.sha)} "Open in Remote") `; commandBar += `[\`${GlyphChars.ArrowUpRight}\`](${OpenCommitInRemoteCommand.getMarkdownCommandArgs(commit.sha)} "Open in Remote") `;
} }
@ -71,7 +71,7 @@ export class Annotations {
return commandBar; return commandBar;
} }
static getHoverMessage(commit: GitCommit, dateFormat: string | null, hasRemotes: boolean, annotationType?: FileAnnotationType): MarkdownString {
static getHoverMessage(commit: GitCommit, dateFormat: string | null, hasRemote: boolean, annotationType?: FileAnnotationType): MarkdownString {
if (dateFormat === null) { if (dateFormat === null) {
dateFormat = 'MMMM Do, YYYY h:MMa'; dateFormat = 'MMMM Do, YYYY h:MMa';
} }
@ -80,7 +80,7 @@ export class Annotations {
let commandBar = ''; let commandBar = '';
let showCommitDetailsCommand = ''; let showCommitDetailsCommand = '';
if (!commit.isUncommitted) { if (!commit.isUncommitted) {
commandBar = `\n\n${this.getHoverCommandBar(commit, hasRemotes, annotationType)}`;
commandBar = `\n\n${this.getHoverCommandBar(commit, hasRemote, annotationType)}`;
showCommitDetailsCommand = `[\`${commit.shortSha}\`](${ShowQuickCommitDetailsCommand.getMarkdownCommandArgs(commit.sha)} "Show Commit Details")`; showCommitDetailsCommand = `[\`${commit.shortSha}\`](${ShowQuickCommitDetailsCommand.getMarkdownCommandArgs(commit.sha)} "Show Commit Details")`;
message = commit.message message = commit.message
@ -129,8 +129,8 @@ export class Annotations {
} as DecorationOptions; } as DecorationOptions;
} }
static detailsHover(commit: GitCommit, dateFormat: string | null, hasRemotes: boolean, annotationType?: FileAnnotationType): DecorationOptions {
const message = this.getHoverMessage(commit, dateFormat, hasRemotes, annotationType);
static detailsHover(commit: GitCommit, dateFormat: string | null, hasRemote: boolean, annotationType?: FileAnnotationType): DecorationOptions {
const message = this.getHoverMessage(commit, dateFormat, hasRemote, annotationType);
return { return {
hoverMessage: message hoverMessage: message
} as DecorationOptions; } as DecorationOptions;

+ 1
- 1
src/annotations/blameAnnotationProvider.ts View File

@ -103,7 +103,7 @@ export abstract class BlameAnnotationProviderBase extends AnnotationProviderBase
} }
} }
const message = Annotations.getHoverMessage(logCommit || commit, this._config.defaultDateFormat, await this.git.hasRemotes(commit.repoPath), this._config.blame.file.annotationType);
const message = Annotations.getHoverMessage(logCommit || commit, this._config.defaultDateFormat, await this.git.hasRemote(commit.repoPath), this._config.blame.file.annotationType);
return new Hover(message, document.validateRange(new Range(position.line, 0, position.line, endOfLineIndex))); return new Hover(message, document.validateRange(new Range(position.line, 0, position.line, endOfLineIndex)));
} }

+ 1
- 1
src/annotations/recentChangesAnnotationProvider.ts View File

@ -48,7 +48,7 @@ export class RecentChangesAnnotationProvider extends AnnotationProviderBase {
if (cfg.hover.details) { if (cfg.hover.details) {
this._decorations.push({ this._decorations.push({
hoverMessage: Annotations.getHoverMessage(commit, dateFormat, await this.git.hasRemotes(commit.repoPath), this._config.blame.file.annotationType),
hoverMessage: Annotations.getHoverMessage(commit, dateFormat, await this.git.hasRemote(commit.repoPath), this._config.blame.file.annotationType),
range: range range: range
} as DecorationOptions); } as DecorationOptions);
} }

+ 1
- 1
src/constants.ts View File

@ -35,7 +35,7 @@ export enum CommandContext {
GitExplorerView = 'gitlens:gitExplorer:view', GitExplorerView = 'gitlens:gitExplorer:view',
HasRemotes = 'gitlens:hasRemotes', HasRemotes = 'gitlens:hasRemotes',
HasRepository = 'gitlens:hasRepository', HasRepository = 'gitlens:hasRepository',
ActiveHasRemotes = 'gitlens:activeHasRemotes',
ActiveHasRemote = 'gitlens:activeHasRemote',
ActiveIsBlameable = 'gitlens:activeIsBlameable', ActiveIsBlameable = 'gitlens:activeIsBlameable',
ActiveFileIsTracked = 'gitlens:activeIsTracked', ActiveFileIsTracked = 'gitlens:activeIsTracked',
Key = 'gitlens:key' Key = 'gitlens:key'

+ 1
- 1
src/currentLineController.ts View File

@ -427,7 +427,7 @@ export class CurrentLineController extends Disposable {
} }
} }
const message = Annotations.getHoverMessage(logCommit || commit, this._config.defaultDateFormat, await this.git.hasRemotes(commit.repoPath), this._config.blame.file.annotationType);
const message = Annotations.getHoverMessage(logCommit || commit, this._config.defaultDateFormat, await this.git.hasRemote(commit.repoPath), this._config.blame.file.annotationType);
return new Hover(message, range); return new Hover(message, range);
} }

+ 3
- 5
src/git/gitContextTracker.ts View File

@ -191,13 +191,11 @@ export class GitContextTracker extends Disposable {
private async updateRemotes() { private async updateRemotes() {
let hasRemotes = false; let hasRemotes = false;
if (this._context.repo !== undefined) { if (this._context.repo !== undefined) {
hasRemotes = await this._context.repo.hasRemotes();
setCommandContext(CommandContext.ActiveHasRemotes, hasRemotes);
}
else {
setCommandContext(CommandContext.ActiveHasRemotes, false);
hasRemotes = await this._context.repo.hasRemote();
} }
setCommandContext(CommandContext.ActiveHasRemote, hasRemotes);
if (!hasRemotes) { if (!hasRemotes) {
const repositories = await this.git.getRepositories(); const repositories = await this.git.getRepositories();
for (const repo of repositories) { for (const repo of repositories) {

+ 16
- 5
src/git/models/repository.ts View File

@ -65,6 +65,7 @@ export class Repository extends Disposable {
readonly normalizedPath: string; readonly normalizedPath: string;
readonly storage: Map<string, any> = new Map(); readonly storage: Map<string, any> = new Map();
private _branch: Promise<GitBranch | undefined> | undefined;
private readonly _disposable: Disposable; private readonly _disposable: Disposable;
private _fireChangeDebounced: ((e: RepositoryChangeEvent) => void) | undefined = undefined; private _fireChangeDebounced: ((e: RepositoryChangeEvent) => void) | undefined = undefined;
private _fireFileSystemChangeDebounced: ((e: RepositoryFileSystemChangeEvent) => void) | undefined = undefined; private _fireFileSystemChangeDebounced: ((e: RepositoryFileSystemChangeEvent) => void) | undefined = undefined;
@ -72,7 +73,7 @@ export class Repository extends Disposable {
private _fsWatcherDisposable: Disposable | undefined; private _fsWatcherDisposable: Disposable | undefined;
private _pendingChanges: { repo?: RepositoryChangeEvent, fs?: RepositoryFileSystemChangeEvent } = { }; private _pendingChanges: { repo?: RepositoryChangeEvent, fs?: RepositoryFileSystemChangeEvent } = { };
private _providerMap: RemoteProviderMap | undefined; private _providerMap: RemoteProviderMap | undefined;
private _remotes: GitRemote[] | undefined;
private _remotes: Promise<GitRemote[]> | undefined;
private _suspended: boolean; private _suspended: boolean;
constructor( constructor(
@ -148,6 +149,8 @@ export class Repository extends Disposable {
return; return;
} }
this._branch = undefined;
if (uri !== undefined && uri.path.endsWith('refs/remotes')) { if (uri !== undefined && uri.path.endsWith('refs/remotes')) {
this._remotes = undefined; this._remotes = undefined;
this.fireChange(RepositoryChange.Remotes); this.fireChange(RepositoryChange.Remotes);
@ -227,8 +230,11 @@ export class Repository extends Disposable {
return this.folder === workspace.getWorkspaceFolder(uri); return this.folder === workspace.getWorkspaceFolder(uri);
} }
async getBranch(): Promise<GitBranch | undefined> {
return this.git.getBranch(this.path);
getBranch(): Promise<GitBranch | undefined> {
if (this._branch === undefined) {
this._branch = this.git.getBranch(this.path);
}
return this._branch;
} }
async getBranches(): Promise<GitBranch[]> { async getBranches(): Promise<GitBranch[]> {
@ -239,14 +245,14 @@ export class Repository extends Disposable {
return this.git.getChangedFilesCount(this.path, sha); return this.git.getChangedFilesCount(this.path, sha);
} }
async getRemotes(): Promise<GitRemote[]> {
getRemotes(): Promise<GitRemote[]> {
if (this._remotes === undefined) { if (this._remotes === undefined) {
if (this._providerMap === undefined) { if (this._providerMap === undefined) {
const remotesCfg = configuration.get<IRemotesConfig[] | null | undefined>(configuration.name('remotes').value, this.folder.uri); const remotesCfg = configuration.get<IRemotesConfig[] | null | undefined>(configuration.name('remotes').value, this.folder.uri);
this._providerMap = RemoteProviderFactory.createMap(remotesCfg); this._providerMap = RemoteProviderFactory.createMap(remotesCfg);
} }
this._remotes = await this.git.getRemotesCore(this.path, this._providerMap);
this._remotes = this.git.getRemotesCore(this.path, this._providerMap);
} }
return this._remotes; return this._remotes;
@ -260,6 +266,11 @@ export class Repository extends Disposable {
return this.git.getStatusForRepo(this.path); return this.git.getStatusForRepo(this.path);
} }
async hasRemote(): Promise<boolean> {
const branch = await this.getBranch();
return branch !== undefined && branch.tracking !== undefined;
}
async hasRemotes(): Promise<boolean> { async hasRemotes(): Promise<boolean> {
const remotes = await this.getRemotes(); const remotes = await this.getRemotes();
return remotes !== undefined && remotes.length > 0; return remotes !== undefined && remotes.length > 0;

+ 9
- 0
src/gitService.ts View File

@ -992,6 +992,15 @@ export class GitService extends Disposable {
} }
} }
async hasRemote(repoPath: string | undefined): Promise<boolean> {
if (repoPath === undefined) return false;
const repository = await this.getRepository(repoPath);
if (repository === undefined) return false;
return repository.hasRemote();
}
async hasRemotes(repoPath: string | undefined): Promise<boolean> { async hasRemotes(repoPath: string | undefined): Promise<boolean> {
if (repoPath === undefined) return false; if (repoPath === undefined) return false;

Loading…
Cancel
Save