Skip to content

Commit 8e3f5e7

Browse files
committed
Fixes issue with stashes w/ only untracked files
1 parent 1ec0a29 commit 8e3f5e7

File tree

6 files changed

+39
-28
lines changed

6 files changed

+39
-28
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1717
- Removes `gitlens.annotations.file.recentChanges.hover.wholeLine` setting as it didn't really make sense
1818

1919
### Fixed
20+
- Fixes an issue where stashes with only untracked files would not show in the `Stashes` node of the GitLens custom view
2021

2122
## [5.0.0] - 2017-09-12
2223
### Added

src/git/gitUri.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class GitUri extends Uri {
4242
}
4343
else {
4444
const commit = commitOrRepoPath;
45-
base._fsPath = path.resolve(commit.repoPath, commit.originalFileName || commit.fileName);
45+
base._fsPath = path.resolve(commit.repoPath, commit.originalFileName || commit.fileName || '');
4646

4747
if (commit.repoPath !== undefined) {
4848
this.repoPath = commit.repoPath;

src/git/models/commit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export class GitCommit {
7070
}
7171

7272
get uri(): Uri {
73-
return Uri.file(path.resolve(this.repoPath, this.originalFileName || this.fileName));
73+
return Uri.file(path.resolve(this.repoPath, this.originalFileName || this.fileName || ''));
7474
}
7575

7676
private _dateFormatter?: Dates.IDateFormatter;

src/git/models/logCommit.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ export class GitLogCommit extends GitCommit {
4040
this.status = fileStatus.status;
4141
}
4242
else {
43-
this.fileStatuses = [{ status: status, fileName: fileName, originalFileName: originalFileName } as IGitStatusFile];
43+
if (fileName === undefined) {
44+
this.fileStatuses = [];
45+
}
46+
else {
47+
this.fileStatuses = [{ status: status, fileName: fileName, originalFileName: originalFileName } as IGitStatusFile];
48+
}
4449
this.status = status;
4550
}
4651
}

src/git/parsers/stashParser.ts

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,33 @@ interface StashEntry {
1313

1414
export class GitStashParser {
1515

16+
static parse(data: string, repoPath: string): GitStash | undefined {
17+
const entries = this._parseEntries(data);
18+
if (entries === undefined) return undefined;
19+
20+
const commits: Map<string, GitStashCommit> = new Map();
21+
22+
for (let i = 0, len = entries.length; i < len; i++) {
23+
const entry = entries[i];
24+
25+
let commit = commits.get(entry.sha);
26+
if (commit === undefined) {
27+
commit = new GitStashCommit(entry.stashName, repoPath, entry.sha, entry.fileNames, new Date(entry.date! as any * 1000), entry.summary, undefined, entry.fileStatuses) as GitStashCommit;
28+
commits.set(entry.sha, commit);
29+
}
30+
}
31+
32+
return {
33+
repoPath: repoPath,
34+
commits: commits
35+
} as GitStash;
36+
}
37+
1638
private static _parseEntries(data: string): StashEntry[] | undefined {
1739
if (!data) return undefined;
1840

1941
const lines = data.split('\n');
20-
if (!lines.length) return undefined;
42+
if (lines.length === 0) return undefined;
2143

2244
const entries: StashEntry[] = [];
2345

@@ -65,7 +87,12 @@ export class GitStashParser {
6587
case 'filename':
6688
const nextLine = lines[position + 1];
6789
// If the next line isn't blank, make sure it isn't starting a new commit
68-
if (nextLine && Git.shaRegex.test(nextLine)) continue;
90+
if (nextLine && Git.shaRegex.test(nextLine)) {
91+
entries.push(entry);
92+
entry = undefined;
93+
94+
continue;
95+
}
6996

7097
position++;
7198

@@ -108,28 +135,6 @@ export class GitStashParser {
108135
return entries;
109136
}
110137

111-
static parse(data: string, repoPath: string): GitStash | undefined {
112-
const entries = this._parseEntries(data);
113-
if (entries === undefined) return undefined;
114-
115-
const commits: Map<string, GitStashCommit> = new Map();
116-
117-
for (let i = 0, len = entries.length; i < len; i++) {
118-
const entry = entries[i];
119-
120-
let commit = commits.get(entry.sha);
121-
if (commit === undefined) {
122-
commit = new GitStashCommit(entry.stashName, repoPath, entry.sha, entry.fileNames, new Date(entry.date! as any * 1000), entry.summary, undefined, entry.fileStatuses) as GitStashCommit;
123-
commits.set(entry.sha, commit);
124-
}
125-
}
126-
127-
return {
128-
repoPath: repoPath,
129-
commits: commits
130-
} as GitStash;
131-
}
132-
133138
private static _parseFileName(entry: { fileName?: string, originalFileName?: string }) {
134139
if (entry.fileName === undefined) return;
135140

src/git/parsers/statusParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class GitStatusParser {
1717
if (!data) return undefined;
1818

1919
const lines = data.split('\n').filter(_ => !!_);
20-
if (!lines.length) return undefined;
20+
if (lines.length === 0) return undefined;
2121

2222
const status = {
2323
branch: '',

0 commit comments

Comments
 (0)