7 Commits

Author SHA1 Message Date
Eric Amodio
c5f57172e4 Fixes issue where work tree files could no show up 2017-09-23 23:36:43 -04:00
Eric Amodio
dd0a636e24 Preps v5.2.0 2017-09-23 23:29:49 -04:00
Eric Amodio
393ec351f0 Adds gitlens.gitExplorer.includeWorkingTree setting
Adds auto-update for working trree
Fixes issues with working tree status
2017-09-23 16:29:56 -04:00
Eric Amodio
99d6da9c90 Fixes issue with whitespace collapsing in decorations 2017-09-22 01:01:43 -04:00
Eric Amodio
0eb202b8ae Closes #150 - adds auto view to custom view 2017-09-22 00:48:57 -04:00
Eric Amodio
65736a6ce7 Adds watching of creates/deletes inside .git 2017-09-21 18:43:46 -04:00
Eric Amodio
ed42eba8b8 Fixes issue with untracked files being counted properly 2017-09-21 18:43:12 -04:00
13 changed files with 188 additions and 67 deletions

View File

@@ -6,17 +6,20 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
## [Unreleased] ## [Unreleased]
## [5.2.0-beta] - 2017-09-20 ## [5.2.0] - 2017-09-23
### Added ### Added
- Adds working tree status (enabled via `"gitlens.insiders": true`) to the `Repository Status` node in the `GitLens` custom view
- Adds new `Changed Files` node to the `Repository Status` node of the `GitLens` custom view's `Repository View` -- closes [#139](https://github.com/eamodio/vscode-gitlens/issues/139) - Adds new `Changed Files` node to the `Repository Status` node of the `GitLens` custom view's `Repository View` -- closes [#139](https://github.com/eamodio/vscode-gitlens/issues/139)
- Provides a at-a-glance view of all "working" changes - Provides a at-a-glance view of all "working" changes
- Expands to a file-based view of all changed files in the working tree (enabled via `"gitlens.insiders": true`) and/or all files in all commits ahead of the upstream - Expands to a file-based view of all changed files in the working tree (enabled via `"gitlens.insiders": true`) and/or all files in all commits ahead of the upstream
- Adds optional (on by default) working tree status information to the `Repository Status` node in the `GitLens` custom view
- Adds `auto` value to `gitlens.gitExplorer.view` setting - closes [#150](https://github.com/eamodio/vscode-gitlens/issues/150)
- Adds `gitlens.gitExplorer.enabled` setting to specify whether or not to show the `GitLens` custom view - closes [#144](https://github.com/eamodio/vscode-gitlens/issues/144) - Adds `gitlens.gitExplorer.enabled` setting to specify whether or not to show the `GitLens` custom view - closes [#144](https://github.com/eamodio/vscode-gitlens/issues/144)
- Adds `gitlens.gitExplorer.includeWorkingTree` setting to specify whether or not to include working tree files inside the `Repository Status` node of the `GitLens` custom view
- Adds `gitlens.gitExplorer.statusFileFormat` setting to the format of the status of a working or committed file in the `GitLens` custom view - Adds `gitlens.gitExplorer.statusFileFormat` setting to the format of the status of a working or committed file in the `GitLens` custom view
### Changed ### Changed
- Changes the sorting (now alphabetical) of files shown in the `GitLens` custom view - Changes the sorting (now alphabetical) of files shown in the `GitLens` custom view
- Changes the default of the `gitlens.gitExplorer.view` setting to `auto`
- Changes the default of the `gitlens.gitExplorer.commitFormat` setting to add parentheses around the commit id - Changes the default of the `gitlens.gitExplorer.commitFormat` setting to add parentheses around the commit id
- Removes many menu items from `editor/title` & `editor/title/context` by default -- can be re-enabled via the `gitlens.advanced.menus` setting - Removes many menu items from `editor/title` & `editor/title/context` by default -- can be re-enabled via the `gitlens.advanced.menus` setting

View File

@@ -126,7 +126,7 @@ GitLens provides an unobtrusive blame annotation at the end of the current line,
![GitLens Repository view](https://raw.githubusercontent.com/eamodio/vscode-gitlens/master/images/screenshot-git-custom-view-repository.png) ![GitLens Repository view](https://raw.githubusercontent.com/eamodio/vscode-gitlens/master/images/screenshot-git-custom-view-repository.png)
- `Repository Status` node — provides the status of the repository - `Repository Status` node — provides the status of the repository
- Provides the name of the current branch, its working tree status (enabled via `"gitlens.insiders": true`), and its upstream tracking branch and status (if available) - Provides the name of the current branch, [optionally](#gitlens-custom-view-settings) its working tree status, and its upstream tracking branch and status (if available)
- Provides indicator dots on the repository icon which denote the following: - Provides indicator dots on the repository icon which denote the following:
- `None` - up-to-date with the upstream - `None` - up-to-date with the upstream
- `Green` - ahead of the upstream - `Green` - ahead of the upstream
@@ -136,7 +136,7 @@ GitLens provides an unobtrusive blame annotation at the end of the current line,
- is behind the upstream — quickly see and explore the specific commits behind the upstream (i.e. commits that haven't been pulled) - is behind the upstream — quickly see and explore the specific commits behind the upstream (i.e. commits that haven't been pulled)
- is ahead of the upstream — quickly see and explore the specific commits ahead of the upstream (i.e. commits that haven't been pushed) - is ahead of the upstream — quickly see and explore the specific commits ahead of the upstream (i.e. commits that haven't been pushed)
- `Changed Files` node — provides a at-a-glance view of all "working" changes - `Changed Files` node — provides a at-a-glance view of all "working" changes
- Expands to a file-based view of all changed files in the working tree (enabled via `"gitlens.insiders": true`) and/or all files in all commits ahead of the upstream - Expands to a file-based view of all changed files in the working tree ([optionally](#gitlens-custom-view-settings)) and/or all files in all commits ahead of the upstream
- Provides a context menu with `Open Repository in Remote`, and `Refresh` commands - Provides a context menu with `Open Repository in Remote`, and `Refresh` commands
- `Branches` node — provides a list of the local branches - `Branches` node — provides a list of the local branches
@@ -346,7 +346,7 @@ GitLens is highly customizable and provides many configuration settings to allow
|`gitlens.codeLens.recentChange.command`|Specifies the command to be executed when the `recent change` code lens is clicked<br />`gitlens.toggleFileBlame` - toggles file blame annotations<br />`gitlens.showBlameHistory` - opens the blame history explorer<br />`gitlens.showFileHistory` - opens the file history explorer<br />`gitlens.diffWithPrevious` - compares the current committed file with the previous commit<br />`gitlens.showQuickCommitDetails` - shows a commit details quick pick<br />`gitlens.showQuickCommitFileDetails` - shows a commit file details quick pick<br />`gitlens.showQuickFileHistory` - shows a file history quick pick<br />`gitlens.showQuickRepoHistory` - shows a branch history quick pick |`gitlens.codeLens.recentChange.command`|Specifies the command to be executed when the `recent change` code lens is clicked<br />`gitlens.toggleFileBlame` - toggles file blame annotations<br />`gitlens.showBlameHistory` - opens the blame history explorer<br />`gitlens.showFileHistory` - opens the file history explorer<br />`gitlens.diffWithPrevious` - compares the current committed file with the previous commit<br />`gitlens.showQuickCommitDetails` - shows a commit details quick pick<br />`gitlens.showQuickCommitFileDetails` - shows a commit file details quick pick<br />`gitlens.showQuickFileHistory` - shows a file history quick pick<br />`gitlens.showQuickRepoHistory` - shows a branch history quick pick
|`gitlens.codeLens.authors.enabled`|Specifies whether or not to show an `authors` code lens showing number of authors of the file or code block and the most prominent author (if there is more than one) |`gitlens.codeLens.authors.enabled`|Specifies whether or not to show an `authors` code lens showing number of authors of the file or code block and the most prominent author (if there is more than one)
|`gitlens.codeLens.authors.command`|Specifies the command to be executed when the `authors` code lens is clicked<br />`gitlens.toggleFileBlame` - toggles file blame annotations<br />`gitlens.showBlameHistory` - opens the blame history explorer<br />`gitlens.showFileHistory` - opens the file history explorer<br />`gitlens.diffWithPrevious` - compares the current committed file with the previous commit<br />`gitlens.showQuickCommitDetails` - shows a commit details quick pick<br />`gitlens.showQuickCommitFileDetails` - shows a commit file details quick pick<br />`gitlens.showQuickFileHistory` - shows a file history quick pick<br />`gitlens.showQuickRepoHistory` - shows a branch history quick pick |`gitlens.codeLens.authors.command`|Specifies the command to be executed when the `authors` code lens is clicked<br />`gitlens.toggleFileBlame` - toggles file blame annotations<br />`gitlens.showBlameHistory` - opens the blame history explorer<br />`gitlens.showFileHistory` - opens the file history explorer<br />`gitlens.diffWithPrevious` - compares the current committed file with the previous commit<br />`gitlens.showQuickCommitDetails` - shows a commit details quick pick<br />`gitlens.showQuickCommitFileDetails` - shows a commit file details quick pick<br />`gitlens.showQuickFileHistory` - shows a file history quick pick<br />`gitlens.showQuickRepoHistory` - shows a branch history quick pick
|`gitlens.codeLens.locations`|Specifies where Git code lens will be shown in the document<br />`document` - adds code lens at the top of the document<br />`containers` - adds code lens at the start of container-like symbols (modules, classes, interfaces, etc)<br />`blocks` - adds code lens at the start of block-like symbols (functions, methods, properties, etc) lines<br />`custom` - adds code lens at the start of symbols contained in `gitlens.codeLens.locationCustomSymbols` |`gitlens.codeLens.locations`|Specifies where Git code lens will be shown in the document<br />`document` - adds code lens at the top of the document<br />`containers` - adds code lens at the start of container-like symbols (modules, classes, interfaces, etc)<br />`blocks` - adds code lens at the start of block-like symbols (functions, methods, properties, etc) lines<br />`custom` - adds code lens at the start of symbols contained in `gitlens.codeLens.locationCustomSymbols`
|`gitlens.codeLens.customLocationSymbols`|Specifies the set of document symbols where Git code lens will be shown in the document |`gitlens.codeLens.customLocationSymbols`|Specifies the set of document symbols where Git code lens will be shown in the document
|`gitlens.codeLens.perLanguageLocations`|Specifies where Git code lens will be shown in the document for the specified languages |`gitlens.codeLens.perLanguageLocations`|Specifies where Git code lens will be shown in the document for the specified languages
@@ -355,7 +355,8 @@ GitLens is highly customizable and provides many configuration settings to allow
|Name | Description |Name | Description
|-----|------------ |-----|------------
|`gitlens.gitExplorer.enabled`|Specifies whether or not to show the `GitLens` custom view" |`gitlens.gitExplorer.enabled`|Specifies whether or not to show the `GitLens` custom view"
|`gitlens.gitExplorer.view`|Specifies the starting view (mode) of the `GitLens` custom view<br />`history` - shows the commit history of the active file<br />`repository` - shows a repository explorer" |`gitlens.gitExplorer.view`|Specifies the starting view (mode) of the `GitLens` custom view<br /> `auto` - shows the last selected view, defaults to `repository`<br />`history` - shows the commit history of the active file<br />`repository` - shows a repository explorer"
|`gitlens.gitExplorer.includeWorkingTree`|Specifies whether or not to include working tree files inside the `Repository Status` node of the `GitLens` custom view
|`gitlens.gitExplorer.showTrackingBranch`|Specifies whether or not to show the tracking branch when displaying local branches in the `GitLens` custom view" |`gitlens.gitExplorer.showTrackingBranch`|Specifies whether or not to show the tracking branch when displaying local branches in the `GitLens` custom view"
|`gitlens.gitExplorer.commitFormat`|Specifies the format of committed changes in the `GitLens` custom view<br />Available tokens<br /> ${id} - commit id<br /> ${author} - commit author<br /> ${message} - commit message<br /> ${ago} - relative commit date (e.g. 1 day ago)<br /> ${date} - formatted commit date (format specified by `gitlens.statusBar.dateFormat`)<br /> ${authorAgo} - commit author, relative commit date<br />See https://github.com/eamodio/vscode-gitlens/wiki/Advanced-Formatting for advanced formatting |`gitlens.gitExplorer.commitFormat`|Specifies the format of committed changes in the `GitLens` custom view<br />Available tokens<br /> ${id} - commit id<br /> ${author} - commit author<br /> ${message} - commit message<br /> ${ago} - relative commit date (e.g. 1 day ago)<br /> ${date} - formatted commit date (format specified by `gitlens.statusBar.dateFormat`)<br /> ${authorAgo} - commit author, relative commit date<br />See https://github.com/eamodio/vscode-gitlens/wiki/Advanced-Formatting for advanced formatting
|`gitlens.gitExplorer.commitFileFormat`|Specifies the format of a committed file in the `GitLens` custom view<br />Available tokens<br /> ${file} - file name<br /> ${filePath} - file name and path<br /> ${path} - file path |`gitlens.gitExplorer.commitFileFormat`|Specifies the format of a committed file in the `GitLens` custom view<br />Available tokens<br /> ${file} - file name<br /> ${filePath} - file name and path<br /> ${path} - file path

2
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{ {
"name": "gitlens", "name": "gitlens",
"version": "5.2.0-beta", "version": "5.2.0",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@@ -1,6 +1,6 @@
{ {
"name": "gitlens", "name": "gitlens",
"version": "5.2.0-beta", "version": "5.2.0",
"author": { "author": {
"name": "Eric Amodio", "name": "Eric Amodio",
"email": "eamodio@gmail.com" "email": "eamodio@gmail.com"
@@ -303,7 +303,7 @@
"minItems": 1, "minItems": 1,
"maxItems": 4, "maxItems": 4,
"uniqueItems": true, "uniqueItems": true,
"description": "Specifies where Git code lens will be shown in the document\n `document` - adds code lens at the top of the document\n `containers` - adds code lens at the start of container-like symbols (modules, classes, interfaces, etc)\n `blocks` - adds code lens at the start of block-like symbols (functions, methods, properties, etc) lines\n `custom` - adds code lens at the start of symbols contained in `gitlens.codeLens.locationCustomSymbols`" "description": "Specifies where Git code lens will be shown in the document\n `document` - adds code lens at the top of the document\n `containers` - adds code lens at the start of container-like symbols (modules, classes, interfaces, etc)\n `blocks` - adds code lens at the start of block-like symbols (functions, methods, properties, etc) lines\n `custom` - adds code lens at the start of symbols contained in `gitlens.codeLens.locationCustomSymbols`"
}, },
"gitlens.codeLens.customLocationSymbols": { "gitlens.codeLens.customLocationSymbols": {
"type": "array", "type": "array",
@@ -388,7 +388,7 @@
"minItems": 1, "minItems": 1,
"maxItems": 4, "maxItems": 4,
"uniqueItems": true, "uniqueItems": true,
"description": "Specifies where Git code lens will be shown in the document for the specified language\n `document` - adds code lens at the top of the document\n `containers` - adds code lens at the start of container-like symbols (modules, classes, interfaces, etc)\n `blocks` - adds code lens at the start of block-like symbols (functions, methods, properties, etc) lines\n `custom` - adds code lens at the start of symbols contained in `customSymbols`" "description": "Specifies where Git code lens will be shown in the document for the specified language\n `document` - adds code lens at the top of the document\n `containers` - adds code lens at the start of container-like symbols (modules, classes, interfaces, etc)\n `blocks` - adds code lens at the start of block-like symbols (functions, methods, properties, etc) lines\n `custom` - adds code lens at the start of symbols contained in `customSymbols`"
}, },
"customSymbols": { "customSymbols": {
"type": "array", "type": "array",
@@ -428,6 +428,11 @@
"default": true, "default": true,
"description": "Specifies whether or not to show the `GitLens` custom view" "description": "Specifies whether or not to show the `GitLens` custom view"
}, },
"gitlens.gitExplorer.includeWorkingTree": {
"type": "boolean",
"default": true,
"description": "Specifies whether or not to include working tree files inside the `Repository Status` node of the `GitLens` custom view"
},
"gitlens.gitExplorer.showTrackingBranch": { "gitlens.gitExplorer.showTrackingBranch": {
"type": "boolean", "type": "boolean",
"default": true, "default": true,
@@ -450,12 +455,13 @@
}, },
"gitlens.gitExplorer.view": { "gitlens.gitExplorer.view": {
"type": "string", "type": "string",
"default": "repository", "default": "auto",
"enum": [ "enum": [
"auto",
"history", "history",
"repository" "repository"
], ],
"description": "Specifies the starting view (mode) of the `GitLens` custom view\n `history` - shows the commit history of the active file\n `repository` - shows a repository explorer" "description": "Specifies the starting view (mode) of the `GitLens` custom view\n `auto` - shows the last selected view, defaults to `repository`\n `history` - shows the commit history of the active file\n `repository` - shows a repository explorer"
}, },
"gitlens.remotes": { "gitlens.remotes": {
"type": "array", "type": "array",

View File

@@ -109,14 +109,14 @@ export class Annotations {
} }
static gutter(commit: GitCommit, format: string, dateFormatOrFormatOptions: string | null | ICommitFormatOptions, renderOptions: IRenderOptions): DecorationOptions { static gutter(commit: GitCommit, format: string, dateFormatOrFormatOptions: string | null | ICommitFormatOptions, renderOptions: IRenderOptions): DecorationOptions {
const content = Strings.pad(CommitFormatter.fromTemplate(format, commit, dateFormatOrFormatOptions), 1, 1); const message = CommitFormatter.fromTemplate(format, commit, dateFormatOrFormatOptions);
return { return {
renderOptions: { renderOptions: {
before: { before: {
...renderOptions.before, ...renderOptions.before,
...{ ...{
contentText: content contentText: Strings.pad(message.replace(/ /g, GlyphChars.Space), 1, 1)
} }
}, },
dark: { dark: {
@@ -210,10 +210,11 @@ export class Annotations {
truncateMessageAtNewLine: true, truncateMessageAtNewLine: true,
dateFormat: dateFormat dateFormat: dateFormat
} as ICommitFormatOptions); } as ICommitFormatOptions);
return { return {
renderOptions: { renderOptions: {
after: { after: {
contentText: Strings.pad(message, 1, 1) contentText: Strings.pad(message.replace(/ /g, GlyphChars.Space), 1, 1)
}, },
dark: { dark: {
after: { after: {

View File

@@ -319,6 +319,7 @@ export interface IConfig {
gitExplorer: { gitExplorer: {
enabled: boolean; enabled: boolean;
view: GitExplorerView; view: GitExplorerView;
includeWorkingTree: boolean;
showTrackingBranch: boolean; showTrackingBranch: boolean;
commitFormat: string; commitFormat: string;
commitFileFormat: string; commitFileFormat: string;

View File

@@ -109,7 +109,12 @@ export const GlyphChars = {
ZeroWidthSpace: '\u200b' as GlyphChars ZeroWidthSpace: '\u200b' as GlyphChars
}; };
export type WorkspaceState = 'gitlensVersion'; export type GlobalState = 'gitlensVersion';
export const GlobalState = {
GitLensVersion: 'gitlensVersion' as GlobalState
};
export type WorkspaceState = 'gitlens:gitExplorer:view';
export const WorkspaceState = { export const WorkspaceState = {
GitLensVersion: 'gitlensVersion' as WorkspaceState GitExplorerView: 'gitlens:gitExplorer:view' as WorkspaceState
}; };

View File

@@ -16,7 +16,7 @@ import { ShowQuickRepoStatusCommand, ShowQuickStashListCommand } from './command
import { StashApplyCommand, StashDeleteCommand, StashSaveCommand } from './commands'; import { StashApplyCommand, StashDeleteCommand, StashSaveCommand } from './commands';
import { ToggleCodeLensCommand } from './commands'; import { ToggleCodeLensCommand } from './commands';
import { CodeLensLocations, IConfig, LineHighlightLocations } from './configuration'; import { CodeLensLocations, IConfig, LineHighlightLocations } from './configuration';
import { ApplicationInsightsKey, CommandContext, ExtensionKey, QualifiedExtensionId, setCommandContext, WorkspaceState } from './constants'; import { ApplicationInsightsKey, CommandContext, ExtensionKey, GlobalState, QualifiedExtensionId, setCommandContext } from './constants';
import { CodeLensController } from './codeLensController'; import { CodeLensController } from './codeLensController';
import { CurrentLineController, LineAnnotationType } from './currentLineController'; import { CurrentLineController, LineAnnotationType } from './currentLineController';
import { RemoteProviderFactory } from './git/remotes/factory'; import { RemoteProviderFactory } from './git/remotes/factory';
@@ -71,7 +71,7 @@ export async function activate(context: ExtensionContext) {
notifyOnUnsupportedGitVersion(context, gitVersion); notifyOnUnsupportedGitVersion(context, gitVersion);
notifyOnNewGitLensVersion(context, gitlensVersion); notifyOnNewGitLensVersion(context, gitlensVersion);
await context.globalState.update(WorkspaceState.GitLensVersion, gitlensVersion); await context.globalState.update(GlobalState.GitLensVersion, gitlensVersion);
const git = new GitService(repoPath); const git = new GitService(repoPath);
context.subscriptions.push(git); context.subscriptions.push(git);
@@ -148,7 +148,7 @@ export async function activate(context: ExtensionContext) {
export function deactivate() { } export function deactivate() { }
async function migrateSettings(context: ExtensionContext) { async function migrateSettings(context: ExtensionContext) {
const previousVersion = context.globalState.get<string>(WorkspaceState.GitLensVersion); const previousVersion = context.globalState.get<string>(GlobalState.GitLensVersion);
if (previousVersion === undefined) return; if (previousVersion === undefined) return;
const [major] = previousVersion.split('.'); const [major] = previousVersion.split('.');
@@ -274,7 +274,7 @@ async function migrateSettings(context: ExtensionContext) {
async function notifyOnNewGitLensVersion(context: ExtensionContext, version: string) { async function notifyOnNewGitLensVersion(context: ExtensionContext, version: string) {
if (context.globalState.get(SuppressedKeys.UpdateNotice, false)) return; if (context.globalState.get(SuppressedKeys.UpdateNotice, false)) return;
const previousVersion = context.globalState.get<string>(WorkspaceState.GitLensVersion); const previousVersion = context.globalState.get<string>(GlobalState.GitLensVersion);
if (previousVersion === undefined) { if (previousVersion === undefined) {
Logger.log(`GitLens first-time install`); Logger.log(`GitLens first-time install`);

View File

@@ -340,6 +340,14 @@ export class Git {
return gitCommand({ cwd: repoPath }, ...params, ...search); return gitCommand({ cwd: repoPath }, ...params, ...search);
} }
static log_shortstat(repoPath: string, sha?: string) {
const params = [`log`, `--shortstat`, `--oneline`];
if (sha) {
params.push(sha);
}
return gitCommand({ cwd: repoPath }, ...params);
}
static async ls_files(repoPath: string, fileName: string): Promise<string> { static async ls_files(repoPath: string, fileName: string): Promise<string> {
try { try {
return await gitCommand({ cwd: repoPath, overrideErrorHandling: true }, 'ls-files', fileName); return await gitCommand({ cwd: repoPath, overrideErrorHandling: true }, 'ls-files', fileName);

View File

@@ -86,6 +86,11 @@ export class GitService extends Disposable {
return this._onDidChangeGitCache.event; return this._onDidChangeGitCache.event;
} }
private _onDidChangeFileSystem = new EventEmitter<Uri>();
get onDidChangeFileSystem(): Event<Uri> {
return this._onDidChangeFileSystem.event;
}
private _onDidChangeRepo = new EventEmitter<RepoChangedReasons[]>(); private _onDidChangeRepo = new EventEmitter<RepoChangedReasons[]>();
get onDidChangeRepo(): Event<RepoChangedReasons[]> { get onDidChangeRepo(): Event<RepoChangedReasons[]> {
return this._onDidChangeRepo.event; return this._onDidChangeRepo.event;
@@ -121,14 +126,16 @@ export class GitService extends Disposable {
} }
dispose() { dispose() {
this.stopWatchingFileSystem();
this._repoWatcher && this._repoWatcher.dispose();
this._repoWatcher = undefined;
this._disposable && this._disposable.dispose(); this._disposable && this._disposable.dispose();
this._cacheDisposable && this._cacheDisposable.dispose(); this._cacheDisposable && this._cacheDisposable.dispose();
this._cacheDisposable = undefined; this._cacheDisposable = undefined;
this._repoWatcher && this._repoWatcher.dispose();
this._repoWatcher = undefined;
this._gitCache.clear(); this._gitCache.clear();
this._remotesCache.clear(); this._remotesCache.clear();
this._uriCache.clear(); this._uriCache.clear();
@@ -156,6 +163,8 @@ export class GitService extends Disposable {
disposables.push(workspace.onDidChangeTextDocument(this._onTextDocumentChanged, this)); disposables.push(workspace.onDidChangeTextDocument(this._onTextDocumentChanged, this));
disposables.push(workspace.onDidSaveTextDocument(d => this._removeCachedEntry(d, RemoveCacheReason.DocumentSaved))); disposables.push(workspace.onDidSaveTextDocument(d => this._removeCachedEntry(d, RemoveCacheReason.DocumentSaved)));
disposables.push(this._repoWatcher.onDidChange(this._onRepoChanged, this)); disposables.push(this._repoWatcher.onDidChange(this._onRepoChanged, this));
disposables.push(this._repoWatcher.onDidCreate(this._onRepoChanged, this));
disposables.push(this._repoWatcher.onDidDelete(this._onRepoChanged, this));
this._cacheDisposable = Disposable.from(...disposables); this._cacheDisposable = Disposable.from(...disposables);
} }
@@ -600,7 +609,8 @@ export class GitService extends Disposable {
} }
async getChangedFilesCount(repoPath: string, sha?: string): Promise<GitDiffShortStat | undefined> { async getChangedFilesCount(repoPath: string, sha?: string): Promise<GitDiffShortStat | undefined> {
return GitDiffParser.parseShortStat(await Git.diff_shortstat(repoPath, sha)); const data = await Git.diff_shortstat(repoPath, sha);
return GitDiffParser.parseShortStat(data);
} }
async getConfig(key: string, repoPath?: string): Promise<string> { async getConfig(key: string, repoPath?: string): Promise<string> {
@@ -1032,6 +1042,33 @@ export class GitService extends Disposable {
return Git.difftool_dirDiff(repoPath, sha1, sha2); return Git.difftool_dirDiff(repoPath, sha1, sha2);
} }
private _fsWatcherDisposable: Disposable | undefined;
startWatchingFileSystem() {
if (this._fsWatcherDisposable !== undefined) return;
const debouncedFn = Functions.debounce((uri: Uri) => this._onDidChangeFileSystem.fire(uri), 2500);
const fn = (uri: Uri) => {
// Ignore .git changes
if (/\.git/.test(uri.fsPath)) return;
debouncedFn(uri);
};
const watcher = workspace.createFileSystemWatcher(`**`);
this._fsWatcherDisposable = Disposable.from(
watcher,
watcher.onDidChange(fn),
watcher.onDidCreate(fn),
watcher.onDidDelete(fn)
);
}
stopWatchingFileSystem() {
this._fsWatcherDisposable && this._fsWatcherDisposable.dispose();
this._fsWatcherDisposable = undefined;
}
stashApply(repoPath: string, stashName: string, deleteAfter: boolean = false) { stashApply(repoPath: string, stashName: string, deleteAfter: boolean = false) {
Logger.log(`stashApply('${repoPath}', ${stashName}, ${deleteAfter})`); Logger.log(`stashApply('${repoPath}', ${stashName}, ${deleteAfter})`);

View File

@@ -4,16 +4,18 @@ import { commands, Event, EventEmitter, ExtensionContext, TextDocumentShowOption
import { Commands, DiffWithCommandArgs, DiffWithCommandArgsRevision, DiffWithPreviousCommandArgs, DiffWithWorkingCommandArgs, openEditor, OpenFileInRemoteCommandArgs } from '../commands'; import { Commands, DiffWithCommandArgs, DiffWithCommandArgsRevision, DiffWithPreviousCommandArgs, DiffWithWorkingCommandArgs, openEditor, OpenFileInRemoteCommandArgs } from '../commands';
import { UriComparer } from '../comparers'; import { UriComparer } from '../comparers';
import { ExtensionKey, IConfig } from '../configuration'; import { ExtensionKey, IConfig } from '../configuration';
import { CommandContext, setCommandContext } from '../constants'; import { CommandContext, setCommandContext, WorkspaceState } from '../constants';
import { BranchHistoryNode, CommitFileNode, CommitNode, ExplorerNode, HistoryNode, MessageNode, RepositoryNode, StashNode } from './explorerNodes'; import { BranchHistoryNode, CommitFileNode, CommitNode, ExplorerNode, HistoryNode, MessageNode, RepositoryNode, StashNode } from './explorerNodes';
import { GitService, GitUri, RepoChangedReasons } from '../gitService'; import { GitService, GitUri, RepoChangedReasons } from '../gitService';
export * from './explorerNodes'; export * from './explorerNodes';
export type GitExplorerView = export type GitExplorerView =
'auto' |
'history' | 'history' |
'repository'; 'repository';
export const GitExplorerView = { export const GitExplorerView = {
Auto: 'auto' as GitExplorerView,
History: 'history' as GitExplorerView, History: 'history' as GitExplorerView,
Repository: 'repository' as GitExplorerView Repository: 'repository' as GitExplorerView
}; };
@@ -31,7 +33,7 @@ export class GitExplorer implements TreeDataProvider<ExplorerNode> {
private _config: IConfig; private _config: IConfig;
private _root?: ExplorerNode; private _root?: ExplorerNode;
private _view: GitExplorerView = GitExplorerView.Repository; private _view: GitExplorerView | undefined;
private _onDidChangeTreeData = new EventEmitter<ExplorerNode>(); private _onDidChangeTreeData = new EventEmitter<ExplorerNode>();
public get onDidChangeTreeData(): Event<ExplorerNode> { public get onDidChangeTreeData(): Event<ExplorerNode> {
@@ -62,10 +64,6 @@ export class GitExplorer implements TreeDataProvider<ExplorerNode> {
context.subscriptions.push(workspace.onDidChangeConfiguration(this.onConfigurationChanged, this)); context.subscriptions.push(workspace.onDidChangeConfiguration(this.onConfigurationChanged, this));
this.onConfigurationChanged(); this.onConfigurationChanged();
this._view = this._config.gitExplorer.view;
setCommandContext(CommandContext.GitExplorerView, this._view);
this._root = this.getRootNode();
} }
async getTreeItem(node: ExplorerNode): Promise<TreeItem> { async getTreeItem(node: ExplorerNode): Promise<TreeItem> {
@@ -83,14 +81,14 @@ export class GitExplorer implements TreeDataProvider<ExplorerNode> {
} }
private getRootNode(editor?: TextEditor): ExplorerNode | undefined { private getRootNode(editor?: TextEditor): ExplorerNode | undefined {
const uri = new GitUri(Uri.file(this.git.repoPath), { repoPath: this.git.repoPath, fileName: this.git.repoPath });
switch (this._view) { switch (this._view) {
case GitExplorerView.History: return this.getHistoryNode(editor || window.activeTextEditor); case GitExplorerView.History:
case GitExplorerView.Repository: return new RepositoryNode(uri, this.context, this.git); return this.getHistoryNode(editor || window.activeTextEditor);
}
return undefined; default:
const uri = new GitUri(Uri.file(this.git.repoPath), { repoPath: this.git.repoPath, fileName: this.git.repoPath });
return new RepositoryNode(uri, this.context, this.git);
}
} }
private getHistoryNode(editor: TextEditor | undefined): ExplorerNode | undefined { private getHistoryNode(editor: TextEditor | undefined): ExplorerNode | undefined {
@@ -116,16 +114,21 @@ export class GitExplorer implements TreeDataProvider<ExplorerNode> {
private onConfigurationChanged() { private onConfigurationChanged() {
const cfg = workspace.getConfiguration().get<IConfig>(ExtensionKey)!; const cfg = workspace.getConfiguration().get<IConfig>(ExtensionKey)!;
if (!Objects.areEquivalent(cfg.gitExplorer, this._config && this._config.gitExplorer) || const changed = !Objects.areEquivalent(cfg.gitExplorer, this._config && this._config.gitExplorer);
!Objects.areEquivalent(cfg.insiders, this._config && this._config.insiders)) {
setTimeout(() => {
this._root = this.getRootNode(window.activeTextEditor);
this.refresh();
}, 1);
}
this._config = cfg; this._config = cfg;
}
if (changed) {
let view = cfg.gitExplorer.view;
if (view === GitExplorerView.Auto) {
view = this.context.workspaceState.get<GitExplorerView>(WorkspaceState.GitExplorerView, GitExplorerView.Repository);
}
this.setView(view);
this._root = this.getRootNode(window.activeTextEditor);
this.refresh();
}
}
private onRepoChanged(reasons: RepoChangedReasons[]) { private onRepoChanged(reasons: RepoChangedReasons[]) {
if (this._view !== GitExplorerView.Repository) return; if (this._view !== GitExplorerView.Repository) return;
@@ -149,12 +152,26 @@ export class GitExplorer implements TreeDataProvider<ExplorerNode> {
this.refresh(node); this.refresh(node);
} }
switchTo(view: GitExplorerView) { setView(view: GitExplorerView) {
if (this._view === view) return; if (this._view === view) return;
if (this._config.gitExplorer.view === GitExplorerView.Auto) {
this.context.workspaceState.update(WorkspaceState.GitExplorerView, view);
}
this._view = view; this._view = view;
setCommandContext(CommandContext.GitExplorerView, this._view); setCommandContext(CommandContext.GitExplorerView, this._view);
if (view !== GitExplorerView.Repository) {
this.git.stopWatchingFileSystem();
}
}
switchTo(view: GitExplorerView) {
if (this._view === view) return;
this.setView(view);
this._root = this.getRootNode(window.activeTextEditor); this._root = this.getRootNode(window.activeTextEditor);
this.refresh(); this.refresh();
} }

View File

@@ -22,23 +22,21 @@ export class StatusFilesNode extends ExplorerNode {
} }
async getChildren(): Promise<ExplorerNode[]> { async getChildren(): Promise<ExplorerNode[]> {
let statuses: IGitStatusFileWithCommit[]; let statuses: IGitStatusFileWithCommit[] = [];
let log: GitLog | undefined; let log: GitLog | undefined;
if (this.range !== undefined) { if (this.range !== undefined) {
log = await this.git.getLogForRepo(this.status.repoPath, this.range, this.maxCount); log = await this.git.getLogForRepo(this.status.repoPath, this.range, this.maxCount);
if (log === undefined) return []; if (log !== undefined) {
statuses = Array.from(Iterables.flatMap(log.commits.values(), c => {
statuses = Array.from(Iterables.flatMap(log.commits.values(), c => { return c.fileStatuses.map(s => {
return c.fileStatuses.map(s => { return { ...s, commit: c } as IGitStatusFileWithCommit;
return { ...s, commit: c } as IGitStatusFileWithCommit; });
}); }));
})); }
}
else {
statuses = [];
} }
if (this.status.files.length !== 0 && this.git.config.insiders) { if (this.status.files.length !== 0 && this.includeWorkingTree) {
statuses.splice(0, 0, ...this.status.files.map(s => { statuses.splice(0, 0, ...this.status.files.map(s => {
return { ...s, commit: new GitLogCommit('file', this.status.repoPath, GitService.uncommittedSha, s.fileName, 'You', new Date(), '', s.status, [s], s.originalFileName, 'HEAD', s.fileName) } as IGitStatusFileWithCommit; return { ...s, commit: new GitLogCommit('file', this.status.repoPath, GitService.uncommittedSha, s.fileName, 'You', new Date(), '', s.status, [s], s.originalFileName, 'HEAD', s.fileName) } as IGitStatusFileWithCommit;
})); }));
@@ -61,8 +59,14 @@ export class StatusFilesNode extends ExplorerNode {
} }
async getTreeItem(): Promise<TreeItem> { async getTreeItem(): Promise<TreeItem> {
const stats = await this.git.getChangedFilesCount(this.status.repoPath, this.git.config.insiders ? this.status.upstream : this.range); let files = (this.status.files !== undefined && this.includeWorkingTree) ? this.status.files.length : 0;
const files = (stats === undefined) ? 0 : stats.files;
if (this.status.upstream !== undefined) {
const stats = await this.git.getChangedFilesCount(this.status.repoPath, `${this.status.upstream}...`);
if (stats !== undefined) {
files += stats.files;
}
}
const label = `${files} file${files > 1 ? 's' : ''} changed`; // ${this.status.upstream === undefined ? '' : ` (ahead of ${this.status.upstream})`}`; const label = `${files} file${files > 1 ? 's' : ''} changed`; // ${this.status.upstream === undefined ? '' : ` (ahead of ${this.status.upstream})`}`;
const item = new TreeItem(label, TreeItemCollapsibleState.Collapsed); const item = new TreeItem(label, TreeItemCollapsibleState.Collapsed);
@@ -74,4 +78,9 @@ export class StatusFilesNode extends ExplorerNode {
return item; return item;
} }
private get includeWorkingTree(): boolean {
return this.git.config.gitExplorer.includeWorkingTree;
}
} }

View File

@@ -1,9 +1,11 @@
import { ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode'; import { commands, Disposable, ExtensionContext, TreeItem, TreeItemCollapsibleState, Uri } from 'vscode';
import { ExplorerNode, ResourceType } from './explorerNode'; import { ExplorerNode, ResourceType } from './explorerNode';
import { GitService, GitUri } from '../gitService'; import { GitService, GitStatus, GitUri } from '../gitService';
import { StatusFilesNode } from './statusFilesNode'; import { StatusFilesNode } from './statusFilesNode';
import { StatusUpstreamNode } from './statusUpstreamNode'; import { StatusUpstreamNode } from './statusUpstreamNode';
let _eventDisposable: Disposable | undefined;
export class StatusNode extends ExplorerNode { export class StatusNode extends ExplorerNode {
readonly resourceType: ResourceType = 'gitlens:status'; readonly resourceType: ResourceType = 'gitlens:status';
@@ -30,8 +32,8 @@ export class StatusNode extends ExplorerNode {
children.push(new StatusUpstreamNode(status, 'ahead', this.context, this.git)); children.push(new StatusUpstreamNode(status, 'ahead', this.context, this.git));
} }
if (status.state.ahead || (status.files.length !== 0 && this.git.config.insiders)) { if (status.state.ahead || (status.files.length !== 0 && this.includeWorkingTree)) {
const range = status.state.ahead const range = status.upstream
? `${status.upstream}..${status.branch}` ? `${status.upstream}..${status.branch}`
: undefined; : undefined;
children.push(new StatusFilesNode(status, range, this.context, this.git)); children.push(new StatusFilesNode(status, range, this.context, this.git));
@@ -40,12 +42,26 @@ export class StatusNode extends ExplorerNode {
return children; return children;
} }
async getTreeItem(): Promise<TreeItem> { private _status: GitStatus | undefined;
async getTreeItem(): Promise < TreeItem > {
const status = await this.git.getStatusForRepo(this.uri.repoPath!); const status = await this.git.getStatusForRepo(this.uri.repoPath!);
if (status === undefined) return new TreeItem('No repo status'); if (status === undefined) return new TreeItem('No repo status');
if (_eventDisposable !== undefined) {
_eventDisposable.dispose();
_eventDisposable = undefined;
}
if (this.includeWorkingTree) {
this._status = status;
_eventDisposable = this.git.onDidChangeFileSystem(this.onFileSystemChanged, this);
this.git.startWatchingFileSystem();
}
let hasChildren = false; let hasChildren = false;
const hasWorkingChanges = status.files.length !== 0 && this.git.config.insiders; const hasWorkingChanges = status.files.length !== 0 && this.includeWorkingTree;
let label = ''; let label = '';
let iconSuffix = ''; let iconSuffix = '';
if (status.upstream) { if (status.upstream) {
@@ -68,7 +84,7 @@ export class StatusNode extends ExplorerNode {
} }
} }
else { else {
label = `${status.branch} ${hasWorkingChanges ? 'has uncommitted changes' : 'is clean'}`; label = `${status.branch} ${hasWorkingChanges ? 'has uncommitted changes' : this.includeWorkingTree ? 'has no changes' : 'has nothing to commit'}`;
} }
const item = new TreeItem(label, (hasChildren || hasWorkingChanges) ? TreeItemCollapsibleState.Expanded : TreeItemCollapsibleState.None); const item = new TreeItem(label, (hasChildren || hasWorkingChanges) ? TreeItemCollapsibleState.Expanded : TreeItemCollapsibleState.None);
@@ -81,4 +97,21 @@ export class StatusNode extends ExplorerNode {
return item; return item;
} }
private get includeWorkingTree(): boolean {
return this.git.config.gitExplorer.includeWorkingTree;
}
private async onFileSystemChanged(uri: Uri) {
const status = await this.git.getStatusForRepo(this.uri.repoPath!);
// If we haven't changed from having some working changes to none or vice versa then just refresh the node
// This is because of https://github.com/Microsoft/vscode/issues/34789
if (this._status !== undefined && status !== undefined &&
((this._status.files.length === status.files.length) || (this._status.files.length > 0 && status.files.length > 0))) {
commands.executeCommand('gitlens.gitExplorer.refreshNode', this);
}
commands.executeCommand('gitlens.gitExplorer.refresh');
}
} }