From 147301ac05d5c3d14fff6e336dd0984ebe424b7f Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Tue, 6 Feb 2018 18:25:48 -0500 Subject: [PATCH] Adds control over following renames Adds advanced.fileHistoryFollowsRenames setting Adds commands to set rename following to the GitLens explorer --- CHANGELOG.md | 3 +++ README.md | 3 ++- package.json | 34 ++++++++++++++++++++++++++++++++++ src/configuration.ts | 19 +++++++++++++++++-- src/gitService.ts | 6 +++--- src/quickPicks/commitFileDetails.ts | 2 +- src/ui/config.ts | 1 + src/views/gitExplorer.ts | 11 +++++++++-- 8 files changed, 70 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cbb80fc..82596ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ## [Unreleased] ### Added - Adds a tree layout option to branches in the *GitLens* explorer — closes [#258](https://github.com/eamodio/vscode-gitlens/issues/258) thanks to [PR #260](https://github.com/eamodio/vscode-gitlens/pull/260) by Yukai Huang ([@Yukaii](https://github.com/Yukaii))! +- Adds *Follow Renames* command (`gitlens.gitExplorer.setRenameFollowingOn`) to the **GitLens** explorer *History* view to follow file renames in the history +- Adds *Don't Follow Renames* command (`gitlens.gitExplorer.setRenameFollowingOff`) to the **GitLens** explorer *History* view to not follow file renames in the history +- Adds `gitlens.advanced.fileHistoryFollowsRenames` setting to specify whether file histories will follow renames -- will affect how merge commits are shown in histories — closes [#259](https://github.com/eamodio/vscode-gitlens/issues/259) ### Fixed - Fixes [#35](https://github.com/eamodio/vscode-gitlens/issues/35) - Copy Commit Sha to Clipboard not working (linux) diff --git a/README.md b/README.md index 8ac7d90..0cb2a66 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ Here are a few ways you can help — feel free to choose more than one  A [customizable](#gitlens-explorer-settings "Jump to the GitLens Explorer settings") explorer to navigate and explore repositories or file histories. The GitLens explorer provides two views (modes) — a Repository view and a History view. - A toolbar provides *Search Commits*, *Switch to Repository View* or *Switch to History View*, and *Refresh* commands - Quickly switch between views using the *Switch to Repository View* or *Switch to History View* commands - - A context menu provides *Automatic Layout*, *List Layout*, and *Tree Layout* commands + - A context menu provides *Automatic Layout*, *List Layout*, *Tree Layout*, *Enable Automatic Refresh* or *Disable Automatic Refresh*, and *Follow Renames* or *Don't Follow Renames* commands #### Repository view

@@ -595,6 +595,7 @@ See also [Explorer Settings](#explorer-settings "Jump to the Explorer settings") |`gitlens.advanced.blame.sizeThresholdAfterEdit`|Specifies the maximum document size (in lines) allowed to be re-blamed after an edit while still unsaved. Use 0 to specify no maximum |`gitlens.advanced.caching.enabled`|Specifies whether git output will be cached — changing the default is not recommended |`gitlens.advanced.git`|Specifies the git path to use +|`gitlens.advanced.fileHistoryFollowsRenames`|Specifies whether file histories will follow renames -- will affect how merge commits are shown in histories |`gitlens.advanced.maxListItems`|Specifies the maximum number of items to show in a list. Use 0 to specify no maximum |`gitlens.advanced.menus`|Specifies which commands will be added to which menus |`gitlens.advanced.messages`|Specifies which messages should be suppressed diff --git a/package.json b/package.json index d0d544b..e658b34 100644 --- a/package.json +++ b/package.json @@ -779,6 +779,12 @@ "description": "Specifies the git path to use", "scope": "window" }, + "gitlens.advanced.fileHistoryFollowsRenames": { + "type": "boolean", + "default": true, + "description": "Specifies whether file histories will follow renames -- will affect how merge commits are shown in histories", + "scope": "window" + }, "gitlens.advanced.maxListItems": { "type": "number", "default": 200, @@ -1532,6 +1538,16 @@ "category": "GitLens" }, { + "command": "gitlens.gitExplorer.setRenameFollowingOn", + "title": "Follow Renames", + "category": "GitLens" + }, + { + "command": "gitlens.gitExplorer.setRenameFollowingOff", + "title": "Don't Follow Renames", + "category": "GitLens" + }, + { "command": "gitlens.gitExplorer.switchToHistoryView", "title": "Switch to History View", "category": "GitLens", @@ -1946,6 +1962,14 @@ "when": "false" }, { + "command": "gitlens.gitExplorer.setRenameFollowingOn", + "when": "false" + }, + { + "command": "gitlens.gitExplorer.setRenameFollowingOff", + "when": "false" + }, + { "command": "gitlens.gitExplorer.switchToHistoryView", "when": "gitlens:enabled && gitlens:gitExplorer:view == repository" }, @@ -2255,6 +2279,16 @@ "group": "2_gitlens" }, { + "command": "gitlens.gitExplorer.setRenameFollowingOn", + "when": "view == gitlens.gitExplorer && gitlens:gitExplorer:view == history && !config.gitlens.advanced.fileHistoryFollowsRenames", + "group": "2_gitlens_1" + }, + { + "command": "gitlens.gitExplorer.setRenameFollowingOff", + "when": "view == gitlens.gitExplorer && gitlens:gitExplorer:view == history && config.gitlens.advanced.fileHistoryFollowsRenames", + "group": "2_gitlens_1" + }, + { "command": "gitlens.showCommitSearch", "when": "view == gitlens.resultsExplorer", "group": "navigation@1" diff --git a/src/configuration.ts b/src/configuration.ts index 27ee312..d424539 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -110,8 +110,23 @@ export class Configuration { return Functions.propOf(emptyConfig as IConfig, name); } - update(section: string, value: any, target: ConfigurationTarget) { - return workspace.getConfiguration(ExtensionKey).update(section, value, target); + update(section: string, value: any, target: ConfigurationTarget, resource?: Uri | null) { + return workspace + .getConfiguration(ExtensionKey, target === ConfigurationTarget.Global ? undefined : resource!) + .update(section, value, target); + } + + async updateEffective(section: string, value: any, resource: Uri | null = null) { + const inspect = await configuration.inspect(section, resource)!; + if (inspect.workspaceFolderValue !== undefined) { + await configuration.update(section, value, ConfigurationTarget.WorkspaceFolder, resource); + } + else if (inspect.workspaceValue !== undefined) { + await configuration.update(section, value, ConfigurationTarget.Workspace); + } + else { + await configuration.update(section, value, ConfigurationTarget.Global); + } } } diff --git a/src/gitService.ts b/src/gitService.ts index 603ee80..ce1ff9f 100644 --- a/src/gitService.ts +++ b/src/gitService.ts @@ -325,13 +325,13 @@ export class GitService extends Disposable { } async findNextCommit(repoPath: string, fileName: string, ref?: string): Promise { - let log = await this.getLogForFile(repoPath, fileName, { maxCount: 1, ref: ref, reverse: true }); + let log = await this.getLogForFile(repoPath, fileName, { maxCount: 1, ref: ref, renames: true, reverse: true }); let commit = log && Iterables.first(log.commits.values()); if (commit) return commit; const nextFileName = await this.findNextFileName(repoPath, fileName, ref); if (nextFileName) { - log = await this.getLogForFile(repoPath, nextFileName, { maxCount: 1, ref: ref, reverse: true }); + log = await this.getLogForFile(repoPath, nextFileName, { maxCount: 1, ref: ref, renames: true, reverse: true }); commit = log && Iterables.first(log.commits.values()); } @@ -943,7 +943,7 @@ export class GitService extends Disposable { options = { reverse: false, ...options }; if (options.renames === undefined) { - options.renames = true; + options.renames = Container.config.advanced.fileHistoryFollowsRenames; } let key = 'log'; diff --git a/src/quickPicks/commitFileDetails.ts b/src/quickPicks/commitFileDetails.ts index 2003069..a883e55 100644 --- a/src/quickPicks/commitFileDetails.ts +++ b/src/quickPicks/commitFileDetails.ts @@ -242,7 +242,7 @@ export class CommitFileDetailsQuickPick { // If we can't find the commit or the previous commit isn't available (since it isn't trustworthy) if (c === undefined || c.previousSha === undefined) { - log = await Container.git.getLogForFile(commit.repoPath, uri.fsPath, { maxCount: Container.config.advanced.maxListItems, ref: commit.sha }); + log = await Container.git.getLogForFile(commit.repoPath, uri.fsPath, { maxCount: Container.config.advanced.maxListItems, ref: commit.sha, renames: true }); if (log === undefined) return KeyNoopCommand; c = log && log.commits.get(commit.sha); diff --git a/src/ui/config.ts b/src/ui/config.ts index e744983..be7cb9f 100644 --- a/src/ui/config.ts +++ b/src/ui/config.ts @@ -107,6 +107,7 @@ export interface IAdvancedConfig { }; git: string; + fileHistoryFollowsRenames: boolean; maxListItems: number; menus: { diff --git a/src/views/gitExplorer.ts b/src/views/gitExplorer.ts index beab9f1..e57ba6a 100644 --- a/src/views/gitExplorer.ts +++ b/src/views/gitExplorer.ts @@ -45,6 +45,8 @@ export class GitExplorer extends Disposable implements TreeDataProvider this.setAutoRefresh(Container.config.gitExplorer.autoRefresh, true), this); commands.registerCommand('gitlens.gitExplorer.setAutoRefreshToOff', () => this.setAutoRefresh(Container.config.gitExplorer.autoRefresh, false), this); + commands.registerCommand('gitlens.gitExplorer.setRenameFollowingOn', () => this.setRenameFollowing(true), this); + commands.registerCommand('gitlens.gitExplorer.setRenameFollowingOff', () => this.setRenameFollowing(false), this); commands.registerCommand('gitlens.gitExplorer.switchToHistoryView', () => this.switchTo(GitExplorerView.History), this); commands.registerCommand('gitlens.gitExplorer.switchToRepositoryView', () => this.switchTo(GitExplorerView.Repository), this); @@ -75,7 +77,8 @@ export class GitExplorer extends Disposable implements TreeDataProvider