From 858d9ec578f39486cdff13380a725773811ff8dd Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Fri, 15 Sep 2017 03:27:58 -0400 Subject: [PATCH] Fixes issue with stashes w/ only untracked files --- CHANGELOG.md | 1 + src/git/gitUri.ts | 2 +- src/git/models/commit.ts | 2 +- src/git/models/logCommit.ts | 7 +++++- src/git/parsers/stashParser.ts | 53 ++++++++++++++++++++++------------------- src/git/parsers/statusParser.ts | 2 +- 6 files changed, 39 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4bf1a44..97c9a34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p - Removes `gitlens.annotations.file.recentChanges.hover.wholeLine` setting as it didn't really make sense ### Fixed +- Fixes an issue where stashes with only untracked files would not show in the `Stashes` node of the GitLens custom view ## [5.0.0] - 2017-09-12 ### Added diff --git a/src/git/gitUri.ts b/src/git/gitUri.ts index 4cd964c..afa9e23 100644 --- a/src/git/gitUri.ts +++ b/src/git/gitUri.ts @@ -42,7 +42,7 @@ export class GitUri extends Uri { } else { const commit = commitOrRepoPath; - base._fsPath = path.resolve(commit.repoPath, commit.originalFileName || commit.fileName); + base._fsPath = path.resolve(commit.repoPath, commit.originalFileName || commit.fileName || ''); if (commit.repoPath !== undefined) { this.repoPath = commit.repoPath; diff --git a/src/git/models/commit.ts b/src/git/models/commit.ts index 651e9b4..a7706b2 100644 --- a/src/git/models/commit.ts +++ b/src/git/models/commit.ts @@ -70,7 +70,7 @@ export class GitCommit { } get uri(): Uri { - return Uri.file(path.resolve(this.repoPath, this.originalFileName || this.fileName)); + return Uri.file(path.resolve(this.repoPath, this.originalFileName || this.fileName || '')); } private _dateFormatter?: Dates.IDateFormatter; diff --git a/src/git/models/logCommit.ts b/src/git/models/logCommit.ts index a141012..ca7adf7 100644 --- a/src/git/models/logCommit.ts +++ b/src/git/models/logCommit.ts @@ -40,7 +40,12 @@ export class GitLogCommit extends GitCommit { this.status = fileStatus.status; } else { - this.fileStatuses = [{ status: status, fileName: fileName, originalFileName: originalFileName } as IGitStatusFile]; + if (fileName === undefined) { + this.fileStatuses = []; + } + else { + this.fileStatuses = [{ status: status, fileName: fileName, originalFileName: originalFileName } as IGitStatusFile]; + } this.status = status; } } diff --git a/src/git/parsers/stashParser.ts b/src/git/parsers/stashParser.ts index 7bf3228..41ae97f 100644 --- a/src/git/parsers/stashParser.ts +++ b/src/git/parsers/stashParser.ts @@ -13,11 +13,33 @@ interface StashEntry { export class GitStashParser { + static parse(data: string, repoPath: string): GitStash | undefined { + const entries = this._parseEntries(data); + if (entries === undefined) return undefined; + + const commits: Map = new Map(); + + for (let i = 0, len = entries.length; i < len; i++) { + const entry = entries[i]; + + let commit = commits.get(entry.sha); + if (commit === undefined) { + commit = new GitStashCommit(entry.stashName, repoPath, entry.sha, entry.fileNames, new Date(entry.date! as any * 1000), entry.summary, undefined, entry.fileStatuses) as GitStashCommit; + commits.set(entry.sha, commit); + } + } + + return { + repoPath: repoPath, + commits: commits + } as GitStash; + } + private static _parseEntries(data: string): StashEntry[] | undefined { if (!data) return undefined; const lines = data.split('\n'); - if (!lines.length) return undefined; + if (lines.length === 0) return undefined; const entries: StashEntry[] = []; @@ -65,7 +87,12 @@ export class GitStashParser { case 'filename': const nextLine = lines[position + 1]; // If the next line isn't blank, make sure it isn't starting a new commit - if (nextLine && Git.shaRegex.test(nextLine)) continue; + if (nextLine && Git.shaRegex.test(nextLine)) { + entries.push(entry); + entry = undefined; + + continue; + } position++; @@ -108,28 +135,6 @@ export class GitStashParser { return entries; } - static parse(data: string, repoPath: string): GitStash | undefined { - const entries = this._parseEntries(data); - if (entries === undefined) return undefined; - - const commits: Map = new Map(); - - for (let i = 0, len = entries.length; i < len; i++) { - const entry = entries[i]; - - let commit = commits.get(entry.sha); - if (commit === undefined) { - commit = new GitStashCommit(entry.stashName, repoPath, entry.sha, entry.fileNames, new Date(entry.date! as any * 1000), entry.summary, undefined, entry.fileStatuses) as GitStashCommit; - commits.set(entry.sha, commit); - } - } - - return { - repoPath: repoPath, - commits: commits - } as GitStash; - } - private static _parseFileName(entry: { fileName?: string, originalFileName?: string }) { if (entry.fileName === undefined) return; diff --git a/src/git/parsers/statusParser.ts b/src/git/parsers/statusParser.ts index 50b732d..89c096b 100644 --- a/src/git/parsers/statusParser.ts +++ b/src/git/parsers/statusParser.ts @@ -17,7 +17,7 @@ export class GitStatusParser { if (!data) return undefined; const lines = data.split('\n').filter(_ => !!_); - if (!lines.length) return undefined; + if (lines.length === 0) return undefined; const status = { branch: '',