diff --git a/CHANGELOG.md b/CHANGELOG.md index cb261af..8bef1e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p - Fixes an issue with deep links sometimes failing to properly resolve when a matching repository without the remote is found - Fixes an issue in the _Commit Graph_ where commits not in the history of a merge commit were showing in the same column - Fixes `Reset Stored AI Key` command to work for the current provider +- Fixes an issue with parsing some renames in log output ## [14.3.0] - 2023-09-07 diff --git a/src/git/parsers/logParser.ts b/src/git/parsers/logParser.ts index 98abbcc..c47af41 100644 --- a/src/git/parsers/logParser.ts +++ b/src/git/parsers/logParser.ts @@ -19,7 +19,7 @@ const diffRangeRegex = /^@@ -(\d+?),(\d+?) \+(\d+?),(\d+?) @@/; export const fileStatusRegex = /(\S)\S*\t([^\t\n]+)(?:\t(.+))?/; const fileStatusAndSummaryRegex = /^(\d+?|-)\s+?(\d+?|-)\s+?(.*)(?:\n\s(delete|rename|copy|create))?/; const fileStatusAndSummaryRenamedFileRegex = /(.+)\s=>\s(.+)/; -const fileStatusAndSummaryRenamedFilePathRegex = /(.*?){(.+?)\s=>\s(.*?)}(.*)/; +const fileStatusAndSummaryRenamedFilePathRegex = /(.*?){(.+?)?\s=>\s(.*?)?}(.*)/; const logFileSimpleRegex = /^ (.*)\s*(?:(?:diff --git a\/(.*) b\/(.*))|(?:(\S)\S*\t([^\t\n]+)(?:\t(.+))?))/gm; const logFileSimpleRenamedRegex = /^ (\S+)\s*(.*)$/s; @@ -656,12 +656,27 @@ export class GitLogParser { renamedMatch = fileStatusAndSummaryRenamedFilePathRegex.exec(renamedFileName); if (renamedMatch != null) { + const [, start, from, to, end] = renamedMatch; // If there is no new path, the path part was removed so ensure we don't end up with // - entry.path = - renamedMatch[3] === '' - ? `${renamedMatch[1]}${renamedMatch[4]}`.replace('//', '/') - : `${renamedMatch[1]}${renamedMatch[3]}${renamedMatch[4]}`; - entry.originalPath = `${renamedMatch[1]}${renamedMatch[2]}${renamedMatch[4]}`; + if (!to) { + entry.path = `${ + start.endsWith('/') && end.startsWith('/') + ? start.slice(0, -1) + : start + }${end}`; + } else { + entry.path = `${start}${to}${end}`; + } + + if (!from) { + entry.originalPath = `${ + start.endsWith('/') && end.startsWith('/') + ? start.slice(0, -1) + : start + }${end}`; + } else { + entry.originalPath = `${start}${from}${end}`; + } } else { renamedMatch = fileStatusAndSummaryRenamedFileRegex.exec(renamedFileName);