Browse Source

Disables missed commands when GitLens is disabled

Adds repository creation detection when there are no repositories
main
Eric Amodio 7 years ago
parent
commit
c0f302ee15
6 changed files with 54 additions and 10 deletions
  1. +5
    -0
      CHANGELOG.md
  2. +15
    -3
      package.json
  3. +0
    -1
      src/constants.ts
  4. +1
    -2
      src/extension.ts
  5. +28
    -1
      src/gitService.ts
  6. +5
    -3
      src/system/searchTree.ts

+ 5
- 0
CHANGELOG.md View File

@ -4,6 +4,11 @@ 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/).
## [Unreleased]
### Fixed
- Fixes issue where GitLens wouldn't detect the creation of a Git repository if there were no other repositories open
- Fixes issue where some GitLens commands would show in the palette even though there was no repository
## [7.5.5] - 2018-01-18
### Fixed
- Fixes [#247](https://github.com/eamodio/vscode-gitlens/issues/247) - File annotations button or ESC key does not turn off file annotations

+ 15
- 3
package.json View File

@ -1717,6 +1717,10 @@
"when": "gitlens:activeIsBlameable"
},
{
"command": "gitlens.externalDiff",
"when": "gitlens:enabled"
},
{
"command": "gitlens.externalDiffAll",
"when": "gitlens:enabled"
},
@ -1761,6 +1765,10 @@
"when": "gitlens:enabled"
},
{
"command": "gitlens.showCommitSearch",
"when": "gitlens:enabled"
},
{
"command": "gitlens.showQuickCommitDetails",
"when": "gitlens:activeIsBlameable"
},
@ -1837,6 +1845,10 @@
"when": "gitlens:enabled"
},
{
"command": "gitlens.stashDelete",
"when": "false"
},
{
"command": "gitlens.stashSave",
"when": "gitlens:enabled"
},
@ -2002,11 +2014,11 @@
},
{
"command": "gitlens.gitExplorer.switchToHistoryView",
"when": "gitlens:gitExplorer:view == repository"
"when": "gitlens:enabled && gitlens:gitExplorer:view == repository"
},
{
"command": "gitlens.gitExplorer.switchToRepositoryView",
"when": "gitlens:gitExplorer:view == history"
"when": "gitlens:enabled && gitlens:gitExplorer:view == history"
},
{
"command": "gitlens.resultsExplorer.clearResultsNode",
@ -3278,7 +3290,7 @@
{
"id": "gitlens.gitExplorer",
"name": "GitLens",
"when": "gitlens:enabled && gitlens:gitExplorer && gitlens:hasRepository && config.gitlens.gitExplorer.enabled"
"when": "gitlens:enabled && gitlens:gitExplorer && config.gitlens.gitExplorer.enabled"
},
{
"id": "gitlens.resultsExplorer",

+ 0
- 1
src/constants.ts View File

@ -40,7 +40,6 @@ export enum CommandContext {
GitExplorerAutoRefresh = 'gitlens:gitExplorer:autoRefresh',
GitExplorerView = 'gitlens:gitExplorer:view',
HasRemotes = 'gitlens:hasRemotes',
HasRepository = 'gitlens:hasRepository',
Key = 'gitlens:key',
KeyMap = 'gitlens:keymap',
ResultsExplorer = 'gitlens:resultsExplorer',

+ 1
- 2
src/extension.ts View File

@ -22,10 +22,9 @@ export async function activate(context: ExtensionContext) {
const gitlensVersion = gitlens.packageJSON.version;
const enabled = workspace.getConfiguration('git', null!).get<boolean>('enabled', true);
setCommandContext(CommandContext.Enabled, enabled);
if (!enabled) {
Logger.log(`GitLens(v${gitlensVersion}) was NOT activated -- "git.enabled": false`);
setCommandContext(CommandContext.Enabled, enabled);
return;
}

+ 28
- 1
src/gitService.ts View File

@ -257,7 +257,7 @@ export class GitService extends Disposable {
private async updateContext(repositoryTree: TernarySearchTree<Repository>) {
const hasRepository = repositoryTree.any();
await setCommandContext(CommandContext.HasRepository, hasRepository);
await setCommandContext(CommandContext.Enabled, hasRepository);
let hasRemotes = false;
if (hasRepository) {
@ -268,6 +268,33 @@ export class GitService extends Disposable {
}
await setCommandContext(CommandContext.HasRemotes, hasRemotes);
// If we have no repositories setup a watcher in case one is initialized
if (!hasRepository) {
const watcher = workspace.createFileSystemWatcher('**/.git', false, true, true);
const disposable = Disposable.from(
watcher,
watcher.onDidCreate(async uri => {
const f = workspace.getWorkspaceFolder(uri);
if (f === undefined) return;
// Search for and add all repositories (nested and/or submodules)
const repositories = await this.repositorySearch(f);
if (repositories.length === 0) return;
disposable.dispose();
for (const r of repositories) {
this._repositoryTree.set(r.path, r);
}
await this.updateContext(this._repositoryTree);
// Defer the event trigger enough to let everything unwind
setImmediate(() => this.fireRepositoriesChanged());
}, this)
);
}
}
private fireRepositoriesChanged() {

+ 5
- 3
src/system/searchTree.ts View File

@ -50,8 +50,8 @@ export class StringIterator implements IKeyIterator {
export class PathIterator implements IKeyIterator {
private static _fwd = '/'.charCodeAt(0);
private static _bwd = '\\'.charCodeAt(0);
private static readonly _fwd = '/'.charCodeAt(0);
private static readonly _bwd = '\\'.charCodeAt(0);
private _value: string;
private _from: number;
@ -153,7 +153,7 @@ export class TernarySearchTree {
this._root = undefined;
}
set(key: string, element: E): void {
set(key: string, element: E): E | undefined {
const iter = this._iter.reset(key);
let node: TernarySearchTreeNode<E>;
@ -193,7 +193,9 @@ export class TernarySearchTree {
break;
}
}
const oldElement = node.element;
node.element = element;
return oldElement;
}
get(key: string): E | undefined {

Loading…
Cancel
Save