From ccd0ad67a3e1675cc2f635c7205c6786be31fc59 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Mon, 27 Feb 2017 11:13:42 -0500 Subject: [PATCH] Adds proper support for multiline commit messages Fixes #33 - commit messages needs to be escaped --- src/blameAnnotationFormatter.ts | 4 ++-- src/git/enrichers/logParserEnricher.ts | 4 ++++ src/git/git.ts | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/blameAnnotationFormatter.ts b/src/blameAnnotationFormatter.ts index 60d5a74..5f24fda 100644 --- a/src/blameAnnotationFormatter.ts +++ b/src/blameAnnotationFormatter.ts @@ -65,12 +65,12 @@ export default class BlameAnnotationFormatter { } static getAnnotationHover(config: IBlameConfig, line: IGitCommitLine, commit: GitCommit): string | Array { - const message = commit.message.replace(/\n/g, '\n\n'); + const message = `> \`${commit.message.replace(/\n/g, '\`\n>\n> \`')}\``; if (commit.isUncommitted) { return `\`${'0'.repeat(8)}\`   __Uncommitted changes__`; } - return `\`${commit.sha}\`   __${commit.author}__, ${moment(commit.date).fromNow()} _(${moment(commit.date).format('MMMM Do, YYYY h:MMa')})_ \n\n > ${message}`; + return `\`${commit.sha}\`   __${commit.author}__, ${moment(commit.date).fromNow()} _(${moment(commit.date).format('MMMM Do, YYYY h:MMa')})_ \n\n${message}`; } static getAuthorAndDate(config: IBlameConfig, commit: GitCommit, format?: string, force: boolean = false) { diff --git a/src/git/enrichers/logParserEnricher.ts b/src/git/enrichers/logParserEnricher.ts index 03758db..31b1cae 100644 --- a/src/git/enrichers/logParserEnricher.ts +++ b/src/git/enrichers/logParserEnricher.ts @@ -68,6 +68,10 @@ export class GitLogParserEnricher implements IGitEnricher { case 'summary': entry.summary = lineParts.slice(1).join(' ').trim(); + while (++position < lines.length) { + if (!lines[position]) break; + entry.summary += `\n${lines[position]}`; + } break; case 'filename': diff --git a/src/git/git.ts b/src/git/git.ts index 3d67dc0..cb9a247 100644 --- a/src/git/git.ts +++ b/src/git/git.ts @@ -13,7 +13,7 @@ export * from './enrichers/logParserEnricher'; let git: IGit; const UncommittedRegex = /^[0]+$/; -const DefaultLogParams = [`log`, `--name-status`, `--full-history`, `-m`, `--date=iso8601-strict`, `--format=%H -%nauthor %an%nauthor-date %ai%ncommitter %cn%ncommitter-date %ci%nsummary %s%nfilename ?`]; +const DefaultLogParams = [`log`, `--name-status`, `--full-history`, `-m`, `--date=iso8601-strict`, `--format=%H -%nauthor %an%nauthor-date %ai%ncommitter %cn%ncommitter-date %ci%nsummary %B%nfilename ?`]; async function gitCommand(cwd: string, ...args: any[]) { try {