Browse Source

FIxes issues with open prior blame command

- Adds proper error handling & messaging
  - Handles uncommitted lines
Adds open prior blame to hover on uncommitted lines
main
Eric Amodio 3 years ago
parent
commit
c18dc7b50b
3 changed files with 38 additions and 9 deletions
  1. +30
    -6
      src/commands/openFileAtRevision.ts
  2. +6
    -0
      src/git/formatters/commitFormatter.ts
  3. +2
    -3
      src/hovers/hovers.ts

+ 30
- 6
src/commands/openFileAtRevision.ts View File

@ -54,17 +54,41 @@ export class OpenFileAtRevisionCommand extends ActiveEditorCommand {
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) {
const editorLine = context.editor.selection.active.line;
if (editorLine >= 0) {
try {
const gitUri = await GitUri.fromUri(context.editor.document.uri);
const blame = await Container.instance.git.getBlameForLine(gitUri, blameline);
if (blame != null && !blame.commit.isUncommitted && blame.commit.previousSha != null) {
args.revisionUri = GitUri.toRevisionUri(GitUri.fromCommit(blame.commit, true));
const blame = await Container.instance.git.getBlameForLine(gitUri, editorLine);
if (blame != null) {
if (blame.commit.isUncommitted) {
const diffUris = await blame.commit.getPreviousLineDiffUris(
gitUri,
editorLine,
gitUri.sha,
);
if (diffUris?.previous != null) {
args.revisionUri = GitUri.toRevisionUri(diffUris.previous);
} else {
void Messages.showCommitHasNoPreviousCommitWarningMessage(blame.commit);
return undefined;
}
} else if (blame?.commit.previousSha != null) {
args.revisionUri = GitUri.toRevisionUri(GitUri.fromCommit(blame.commit, true));
} else {
void Messages.showCommitHasNoPreviousCommitWarningMessage(blame.commit);
return undefined;
}
}
} catch {}
} catch (ex) {
Logger.error(ex, 'OpenBlamePriorToChangeCommand');
}
}
}
if (args.revisionUri == null) {
void Messages.showGenericErrorMessage('Unable to open blame');
return undefined;
}
}
return this.execute(context.editor, context.uri, args);

+ 6
- 0
src/git/formatters/commitFormatter.ts View File

@ -294,6 +294,12 @@ export class CommitFormatter extends Formatter {
repoPath: this._item.repoPath,
line: this._options.editor?.line,
})} "Open Changes with Previous Revision")`;
commands += `   [$(versions)](${OpenFileAtRevisionCommand.getMarkdownCommandArgs(
GitUri.toRevisionUri(diffUris.previous),
FileAnnotationType.Blame,
this._options.editor?.line,
)} "Open Blame Prior to this Change")`;
} else {
commands = `\`${this._padOrTruncate(
GitRevision.shorten(

+ 2
- 3
src/hovers/hovers.ts View File

@ -37,6 +37,7 @@ export namespace Hovers {
}
} else {
ref = commit.previousSha;
if (ref == null) return undefined;
}
const line = editorLine + 1;
@ -73,9 +74,7 @@ export namespace Hovers {
let current;
if (commit.isUncommitted) {
const diffUris = await commit.getPreviousLineDiffUris(uri, editorLine, documentRef);
if (diffUris == null || diffUris.previous == null) {
return undefined;
}
if (diffUris?.previous == null) return undefined;
message = `[$(compare-changes)](${DiffWithCommand.getMarkdownCommandArgs({
lhs: {

Loading…
Cancel
Save