瀏覽代碼

Closes #1014 - adds blame prior to change command

main
Eric Amodio 3 年之前
父節點
當前提交
f7ca6f0dfe
共有 6 個文件被更改,包括 87 次插入39 次删除
  1. +11
    -0
      CHANGELOG.md
  2. +1
    -0
      README.md
  3. +11
    -0
      package.json
  4. +2
    -1
      src/commands/common.ts
  5. +28
    -4
      src/commands/openFileAtRevision.ts
  6. +34
    -34
      src/git/formatters/commitFormatter.ts

+ 11
- 0
CHANGELOG.md 查看文件

@ -4,6 +4,17 @@ 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]
### Added
- Adds a new _Open Blame Prior to Change_ command (`gitlens.openBlamePriorToChange`) to open the blame of prior revision of the selected line in the current file — closes [#1014](https://github.com/eamodio/vscode-gitlens/issues/1014)
### Changed
- Changes the _Blame Previous Revision_ command on the hover to _Open Blame Prior to this Change_
- Changes the _Blame Previous Revision_ command icon on the hover to the `versions` codicon
## [11.2.1] - 2021-02-02
### Changed

+ 1
- 0
README.md 查看文件

@ -620,6 +620,7 @@ Additionally, these integrations provide commands to copy the url of or open, fi
- Adds an _Open File_ command (`gitlens.openWorkingFile`) to open the working file for the current file revision
- Adds an _Open Revision..._ command (`gitlens.openFileRevision`) to open the selected revision for the current file
- Adds an _Open Revision from..._ command (`gitlens.openFileRevisionFrom`) to open the revision of the current file from the selected reference
- Adds an _Open Blame Prior to Change_ command (`gitlens.openBlamePriorToChange`) to open the blame of prior revision of the selected line in the current file
- Adds a _Open Changed Files_ command (`gitlens.openChangedFiles`) to open any files with working tree changes
- Adds a _Close Unchanged Files_ command (`gitlens.closeUnchangedFiles`) to close any files without working tree changes

+ 11
- 0
package.json 查看文件

@ -159,6 +159,7 @@
"onCommand:gitlens.copyRemoteFileUrlToClipboard",
"onCommand:gitlens.openFileOnRemoteFrom",
"onCommand:gitlens.copyRemoteFileUrlFrom",
"onCommand:gitlens.openBlamePriorToChange",
"onCommand:gitlens.openFileRevision",
"onCommand:gitlens.openFileRevisionFrom",
"onCommand:gitlens.openPullRequestOnRemote",
@ -3436,6 +3437,12 @@
}
},
{
"command": "gitlens.openBlamePriorToChange",
"title": "Open Blame Prior to Change",
"icon": "$(versions)",
"category": "GitLens"
},
{
"command": "gitlens.openFileRevision",
"title": "Open File at Revision...",
"icon": {
@ -5241,6 +5248,10 @@
"when": "gitlens:activeFileStatus =~ /tracked/ && gitlens:activeFileStatus =~ /remotes/"
},
{
"command": "gitlens.openBlamePriorToChange",
"when": "gitlens:activeFileStatus =~ /tracked/"
},
{
"command": "gitlens.openFileRevision",
"when": "gitlens:activeFileStatus =~ /tracked/"
},

+ 2
- 1
src/commands/common.ts 查看文件

@ -75,9 +75,10 @@ export enum Commands {
ExternalDiffAll = 'gitlens.externalDiffAll',
FetchRepositories = 'gitlens.fetchRepositories',
InviteToLiveShare = 'gitlens.inviteToLiveShare',
OpenChangedFiles = 'gitlens.openChangedFiles',
OpenBlamePriorToChange = 'gitlens.openBlamePriorToChange',
OpenBranchesOnRemote = 'gitlens.openBranchesOnRemote',
OpenBranchOnRemote = 'gitlens.openBranchOnRemote',
OpenChangedFiles = 'gitlens.openChangedFiles',
OpenCommitOnRemote = 'gitlens.openCommitOnRemote',
OpenComparisonOnRemote = 'gitlens.openComparisonOnRemote',
OpenFileFromRemote = 'gitlens.openFileFromRemote',

+ 28
- 4
src/commands/openFileAtRevision.ts 查看文件

@ -1,6 +1,6 @@
'use strict';
import { TextDocumentShowOptions, TextEditor, Uri } from 'vscode';
import { ActiveEditorCommand, command, Commands, getCommandUri } from './common';
import { ActiveEditorCommand, command, CommandContext, Commands, getCommandUri } from './common';
import { FileAnnotationType } from '../configuration';
import { GlyphChars, quickPickTitleMaxChars } from '../constants';
import { Container } from '../container';
@ -46,7 +46,27 @@ export class OpenFileAtRevisionCommand extends ActiveEditorCommand {
}
constructor() {
super(Commands.OpenFileAtRevision);
super([Commands.OpenFileAtRevision, Commands.OpenBlamePriorToChange]);
}
protected async preExecute(context: CommandContext, args?: OpenFileAtRevisionCommandArgs) {
if (context.command === Commands.OpenBlamePriorToChange) {
args = { ...args, annotationType: FileAnnotationType.Blame };
if (args.revisionUri == null && context.editor != null) {
const blameline = context.editor.selection.active.line;
if (blameline >= 0) {
try {
const gitUri = await GitUri.fromUri(context.editor.document.uri);
const blame = await Container.git.getBlameForLine(gitUri, blameline);
if (blame != null && !blame.commit.isUncommitted && blame.commit.previousSha != null) {
args.revisionUri = GitUri.toRevisionUri(GitUri.fromCommit(blame.commit, true));
}
} catch {}
}
}
}
return this.execute(context.editor, context.uri, args);
}
async execute(editor: TextEditor | undefined, uri?: Uri, args?: OpenFileAtRevisionCommandArgs) {
@ -72,14 +92,18 @@ export class OpenFileAtRevisionCommand extends ActiveEditorCommand {
: undefined),
);
const title = `Open File at Revision${Strings.pad(GlyphChars.Dot, 2, 2)}`;
const title = `Open ${
args.annotationType === FileAnnotationType.Blame ? 'Blame' : 'File'
} at Revision${Strings.pad(GlyphChars.Dot, 2, 2)}`;
const pick = await CommitPicker.show(
log,
`${title}${gitUri.getFormattedFilename({
suffix: gitUri.sha ? `:${GitRevision.shorten(gitUri.sha)}` : undefined,
truncateTo: quickPickTitleMaxChars - title.length,
})}`,
'Choose a commit to open the file revision from',
`Choose a commit to ${
args.annotationType === FileAnnotationType.Blame ? 'blame' : 'open'
} the file revision from`,
{
picked: gitUri.sha,
keys: ['right', 'alt+right', 'ctrl+right'],

+ 34
- 34
src/git/formatters/commitFormatter.ts 查看文件

@ -301,12 +301,38 @@ export class CommitFormatter extends Formatter {
commands = `---\n\n[$(git-commit) ${this.id}](${ShowQuickCommitCommand.getMarkdownCommandArgs(
this._item.sha,
)} "Show Commit")${separator}`;
)} "Show Commit")`;
commands += `   [$(compare-changes)](${DiffWithCommand.getMarkdownCommandArgs(
this._item,
this._options.editor?.line,
)} "Open Changes")`;
if (this._item.previousSha != null) {
const uri = GitUri.toRevisionUri(
this._item.previousSha,
this._item.previousUri.fsPath,
this._item.repoPath,
);
commands += `   [$(versions)](${OpenFileAtRevisionCommand.getMarkdownCommandArgs(
uri,
FileAnnotationType.Blame,
this._options.editor?.line,
)} "Open Blame Prior to this Change")`;
}
if (this._options.remotes != null && this._options.remotes.length !== 0) {
const providers = GitRemote.getHighlanderProviders(this._options.remotes);
commands += `   [$(globe)](${OpenCommitOnRemoteCommand.getMarkdownCommandArgs(
this._item.sha,
)} "Open Commit on ${providers?.length ? providers[0].name : 'Remote'}")`;
}
const { pullRequestOrRemote: pr } = this._options;
if (pr != null) {
if (PullRequest.is(pr)) {
commands += `[$(git-pull-request) PR #${
commands += `${separator}[$(git-pull-request) PR #${
pr.id
}](${getMarkdownActionCommand<OpenPullRequestActionContext>('openPullRequest', {
repoPath: this._item.repoPath,
@ -316,46 +342,20 @@ export class CommitFormatter extends Formatter {
Container.actionRunners.count('openPullRequest') == 1 ? ` on ${pr.provider.name}` : '...'
}\n${GlyphChars.Dash.repeat(2)}\n${Strings.escapeMarkdown(pr.title).replace(/"/g, '\\"')}\n${
pr.state
}, ${pr.formatDateFromNow()}")${separator}`;
}, ${pr.formatDateFromNow()}")`;
} else if (pr instanceof Promises.CancellationError) {
commands += `[$(git-pull-request) PR $(loading~spin)](command:${Commands.RefreshHover} "Searching for a Pull Request (if any) that introduced this commit...")${separator}`;
commands += `[$(git-pull-request) PR $(loading~spin)](command:${Commands.RefreshHover} "Searching for a Pull Request (if any) that introduced this commit...")`;
} else if (pr.provider != null && Container.config.integrations.enabled) {
commands += `[$(plug) Connect to ${pr.provider.name}${
GlyphChars.Ellipsis
}](${ConnectRemoteProviderCommand.getMarkdownCommandArgs(pr)} "Connect to ${
pr.provider.name
} to enable the display of the Pull Request (if any) that introduced this commit")${separator}`;
} to enable the display of the Pull Request (if any) that introduced this commit")`;
}
}
commands += `[$(compare-changes)](${DiffWithCommand.getMarkdownCommandArgs(
this._item,
this._options.editor?.line,
)} "Open Changes")${separator}`;
if (this._item.previousSha != null) {
const uri = GitUri.toRevisionUri(
this._item.previousSha,
this._item.previousUri.fsPath,
this._item.repoPath,
);
commands += `[$(history)](${OpenFileAtRevisionCommand.getMarkdownCommandArgs(
uri,
FileAnnotationType.Blame,
this._options.editor?.line,
)} "Blame Previous Revision")${separator}`;
}
if (this._options.remotes != null && this._options.remotes.length !== 0) {
const providers = GitRemote.getHighlanderProviders(this._options.remotes);
commands += `[$(globe)](${OpenCommitOnRemoteCommand.getMarkdownCommandArgs(
this._item.sha,
)} "Open Commit on ${providers?.length ? providers[0].name : 'Remote'}")${separator}`;
}
if (Container.actionRunners.count('hover.commands') > 0) {
commands += `[$(feedback) Discuss / Collab${
commands += `${separator}[$(feedback) Discuss / Collab${
GlyphChars.Ellipsis
}](${getMarkdownActionCommand<HoverCommandsActionContext>('hover.commands', {
repoPath: this._item.repoPath,
@ -374,10 +374,10 @@ export class CommitFormatter extends Formatter {
line: this._options.editor?.line,
}
: undefined,
})} "Want to Discuss or Collaborate? Have Comments, Questions, or Need Help?")${separator}`;
})} "Want to Discuss or Collaborate? Have Comments, Questions, or Need Help?")`;
}
commands += `[$(ellipsis)](${ShowQuickCommitFileCommand.getMarkdownCommandArgs({
commands += `${separator}[$(ellipsis)](${ShowQuickCommitFileCommand.getMarkdownCommandArgs({
revisionUri: GitUri.toRevisionUri(this._item.toGitUri()).toString(true),
})} "Show More Actions")`;

Loading…
取消
儲存