Browse Source

Adds proper support for multiline commit messages

Fixes #33 - commit messages needs to be escaped
main
Eric Amodio 7 years ago
parent
commit
ccd0ad67a3
3 changed files with 7 additions and 3 deletions
  1. +2
    -2
      src/blameAnnotationFormatter.ts
  2. +4
    -0
      src/git/enrichers/logParserEnricher.ts
  3. +1
    -1
      src/git/git.ts

+ 2
- 2
src/blameAnnotationFormatter.ts View File

@ -65,12 +65,12 @@ export default class BlameAnnotationFormatter {
} }
static getAnnotationHover(config: IBlameConfig, line: IGitCommitLine, commit: GitCommit): string | Array<string> { static getAnnotationHover(config: IBlameConfig, line: IGitCommitLine, commit: GitCommit): string | Array<string> {
const message = commit.message.replace(/\n/g, '\n\n');
const message = `> \`${commit.message.replace(/\n/g, '\`\n>\n> \`')}\``;
if (commit.isUncommitted) { if (commit.isUncommitted) {
return `\`${'0'.repeat(8)}\` &nbsp; __Uncommitted changes__`; return `\`${'0'.repeat(8)}\` &nbsp; __Uncommitted changes__`;
} }
return `\`${commit.sha}\` &nbsp; __${commit.author}__, ${moment(commit.date).fromNow()} _(${moment(commit.date).format('MMMM Do, YYYY h:MMa')})_ \n\n > ${message}`;
return `\`${commit.sha}\` &nbsp; __${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) { static getAuthorAndDate(config: IBlameConfig, commit: GitCommit, format?: string, force: boolean = false) {

+ 4
- 0
src/git/enrichers/logParserEnricher.ts View File

@ -68,6 +68,10 @@ export class GitLogParserEnricher implements IGitEnricher {
case 'summary': case 'summary':
entry.summary = lineParts.slice(1).join(' ').trim(); entry.summary = lineParts.slice(1).join(' ').trim();
while (++position < lines.length) {
if (!lines[position]) break;
entry.summary += `\n${lines[position]}`;
}
break; break;
case 'filename': case 'filename':

+ 1
- 1
src/git/git.ts View File

@ -13,7 +13,7 @@ export * from './enrichers/logParserEnricher';
let git: IGit; let git: IGit;
const UncommittedRegex = /^[0]+$/; 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[]) { async function gitCommand(cwd: string, ...args: any[]) {
try { try {

Loading…
Cancel
Save