Skip to content

Commit c0f302e

Browse files
committed
Disables missed commands when GitLens is disabled
Adds repository creation detection when there are no repositories
1 parent 8867bf7 commit c0f302e

File tree

6 files changed

+54
-10
lines changed

6 files changed

+54
-10
lines changed

CHANGELOG.md

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

package.json

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,6 +1716,10 @@
17161716
"command": "gitlens.diffLineWithWorking",
17171717
"when": "gitlens:activeIsBlameable"
17181718
},
1719+
{
1720+
"command": "gitlens.externalDiff",
1721+
"when": "gitlens:enabled"
1722+
},
17191723
{
17201724
"command": "gitlens.externalDiffAll",
17211725
"when": "gitlens:enabled"
@@ -1760,6 +1764,10 @@
17601764
"command": "gitlens.showLastQuickPick",
17611765
"when": "gitlens:enabled"
17621766
},
1767+
{
1768+
"command": "gitlens.showCommitSearch",
1769+
"when": "gitlens:enabled"
1770+
},
17631771
{
17641772
"command": "gitlens.showQuickCommitDetails",
17651773
"when": "gitlens:activeIsBlameable"
@@ -1836,6 +1844,10 @@
18361844
"command": "gitlens.stashApply",
18371845
"when": "gitlens:enabled"
18381846
},
1847+
{
1848+
"command": "gitlens.stashDelete",
1849+
"when": "false"
1850+
},
18391851
{
18401852
"command": "gitlens.stashSave",
18411853
"when": "gitlens:enabled"
@@ -2002,11 +2014,11 @@
20022014
},
20032015
{
20042016
"command": "gitlens.gitExplorer.switchToHistoryView",
2005-
"when": "gitlens:gitExplorer:view == repository"
2017+
"when": "gitlens:enabled && gitlens:gitExplorer:view == repository"
20062018
},
20072019
{
20082020
"command": "gitlens.gitExplorer.switchToRepositoryView",
2009-
"when": "gitlens:gitExplorer:view == history"
2021+
"when": "gitlens:enabled && gitlens:gitExplorer:view == history"
20102022
},
20112023
{
20122024
"command": "gitlens.resultsExplorer.clearResultsNode",
@@ -3278,7 +3290,7 @@
32783290
{
32793291
"id": "gitlens.gitExplorer",
32803292
"name": "GitLens",
3281-
"when": "gitlens:enabled && gitlens:gitExplorer && gitlens:hasRepository && config.gitlens.gitExplorer.enabled"
3293+
"when": "gitlens:enabled && gitlens:gitExplorer && config.gitlens.gitExplorer.enabled"
32823294
},
32833295
{
32843296
"id": "gitlens.resultsExplorer",

src/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ export enum CommandContext {
4040
GitExplorerAutoRefresh = 'gitlens:gitExplorer:autoRefresh',
4141
GitExplorerView = 'gitlens:gitExplorer:view',
4242
HasRemotes = 'gitlens:hasRemotes',
43-
HasRepository = 'gitlens:hasRepository',
4443
Key = 'gitlens:key',
4544
KeyMap = 'gitlens:keymap',
4645
ResultsExplorer = 'gitlens:resultsExplorer',

src/extension.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ export async function activate(context: ExtensionContext) {
2222
const gitlensVersion = gitlens.packageJSON.version;
2323

2424
const enabled = workspace.getConfiguration('git', null!).get<boolean>('enabled', true);
25-
setCommandContext(CommandContext.Enabled, enabled);
26-
2725
if (!enabled) {
2826
Logger.log(`GitLens(v${gitlensVersion}) was NOT activated -- "git.enabled": false`);
27+
setCommandContext(CommandContext.Enabled, enabled);
2928

3029
return;
3130
}

src/gitService.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ export class GitService extends Disposable {
257257

258258
private async updateContext(repositoryTree: TernarySearchTree<Repository>) {
259259
const hasRepository = repositoryTree.any();
260-
await setCommandContext(CommandContext.HasRepository, hasRepository);
260+
await setCommandContext(CommandContext.Enabled, hasRepository);
261261

262262
let hasRemotes = false;
263263
if (hasRepository) {
@@ -268,6 +268,33 @@ export class GitService extends Disposable {
268268
}
269269

270270
await setCommandContext(CommandContext.HasRemotes, hasRemotes);
271+
272+
// If we have no repositories setup a watcher in case one is initialized
273+
if (!hasRepository) {
274+
const watcher = workspace.createFileSystemWatcher('**/.git', false, true, true);
275+
const disposable = Disposable.from(
276+
watcher,
277+
watcher.onDidCreate(async uri => {
278+
const f = workspace.getWorkspaceFolder(uri);
279+
if (f === undefined) return;
280+
281+
// Search for and add all repositories (nested and/or submodules)
282+
const repositories = await this.repositorySearch(f);
283+
if (repositories.length === 0) return;
284+
285+
disposable.dispose();
286+
287+
for (const r of repositories) {
288+
this._repositoryTree.set(r.path, r);
289+
}
290+
291+
await this.updateContext(this._repositoryTree);
292+
293+
// Defer the event trigger enough to let everything unwind
294+
setImmediate(() => this.fireRepositoriesChanged());
295+
}, this)
296+
);
297+
}
271298
}
272299

273300
private fireRepositoriesChanged() {

src/system/searchTree.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ export class StringIterator implements IKeyIterator {
5050

5151
export class PathIterator implements IKeyIterator {
5252

53-
private static _fwd = '/'.charCodeAt(0);
54-
private static _bwd = '\\'.charCodeAt(0);
53+
private static readonly _fwd = '/'.charCodeAt(0);
54+
private static readonly _bwd = '\\'.charCodeAt(0);
5555

5656
private _value: string;
5757
private _from: number;
@@ -153,7 +153,7 @@ export class TernarySearchTree<E> {
153153
this._root = undefined;
154154
}
155155

156-
set(key: string, element: E): void {
156+
set(key: string, element: E): E | undefined {
157157
const iter = this._iter.reset(key);
158158
let node: TernarySearchTreeNode<E>;
159159

@@ -193,7 +193,9 @@ export class TernarySearchTree<E> {
193193
break;
194194
}
195195
}
196+
const oldElement = node.element;
196197
node.element = element;
198+
return oldElement;
197199
}
198200

199201
get(key: string): E | undefined {

0 commit comments

Comments
 (0)