Skip to content

Commit d340d07

Browse files
committed
Fixes #4062 ensure creation of uncommitted commits
1 parent 75a313f commit d340d07

File tree

5 files changed

+68
-40
lines changed

5 files changed

+68
-40
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
88

99
### Fixed
1010

11+
- Fixes regression where hovering over the Graph WIP row doesn't show up anymore ([#4062](https://github.com/gitkraken/vscode-gitlens/issues/4062))
1112
- Fixes Inspect & Graph Details: autolinks rendering when enabled setting is false ([#3841](https://github.com/gitkraken/vscode-gitlens/issues/3841))
1213
- Fixes comparison with Merge Target on Home fails to open a valid comparison ([#4060](https://github.com/gitkraken/vscode-gitlens/issues/4060))
1314

src/env/node/git/sub-providers/commits.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
} from '../../../../git/parsers/logParser';
2828
import { parseGitRefLog, parseGitRefLogDefaultFormat } from '../../../../git/parsers/reflogParser';
2929
import { getGitArgsFromSearchQuery } from '../../../../git/search';
30+
import { createUncommittedChangesCommit } from '../../../../git/utils/-webview/commit.utils';
3031
import { isRevisionRange, isSha, isUncommitted } from '../../../../git/utils/revision.utils';
3132
import { configuration } from '../../../../system/-webview/configuration';
3233
import { splitPath } from '../../../../system/-webview/path';
@@ -59,6 +60,15 @@ export class CommitsGitSubProvider implements GitCommitsSubProvider {
5960

6061
@log()
6162
async getCommit(repoPath: string, rev: string): Promise<GitCommit | undefined> {
63+
if (isUncommitted(rev, true)) {
64+
return createUncommittedChangesCommit(
65+
this.container,
66+
repoPath,
67+
rev,
68+
await this.provider.config.getCurrentUser(repoPath),
69+
);
70+
}
71+
6272
const log = await this.getLog(repoPath, rev, { limit: 2 });
6373
if (log == null) return undefined;
6474

src/git/models/statusFile.ts

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
import type { Uri } from 'vscode';
33
import type { Container } from '../../container';
44
import { memoize } from '../../system/decorators/-webview/memoize';
5+
import { createUncommittedChangesCommit } from '../utils/-webview/commit.utils';
56
import { getGitFileFormattedDirectory, getGitFileFormattedPath } from '../utils/-webview/file.utils';
67
import { getGitFileStatusText } from '../utils/fileStatus.utils';
7-
import { GitCommit, GitCommitIdentity } from './commit';
8+
import type { GitCommit } from './commit';
89
import type { GitFile } from './file';
910
import { GitFileChange } from './fileChange';
1011
import type { GitFileStatus } from './fileStatus';
@@ -140,19 +141,10 @@ export class GitStatusFile implements GitFile {
140141
false,
141142
);
142143
return [
143-
new GitCommit(
144-
container,
145-
this.repoPath,
146-
uncommitted,
147-
new GitCommitIdentity('You', user?.email ?? undefined, now),
148-
new GitCommitIdentity('You', user?.email ?? undefined, now),
149-
'Uncommitted changes',
150-
['HEAD'],
151-
'Uncommitted changes',
152-
{ file: file, files: [file] },
153-
undefined,
154-
[],
155-
),
144+
createUncommittedChangesCommit(container, this.repoPath, uncommitted, user, {
145+
files: { file: file, files: [file] },
146+
parents: ['HEAD'],
147+
}),
156148
];
157149
}
158150

@@ -172,19 +164,10 @@ export class GitStatusFile implements GitFile {
172164
false,
173165
);
174166
commits.push(
175-
new GitCommit(
176-
container,
177-
this.repoPath,
178-
uncommitted,
179-
new GitCommitIdentity('You', user?.email ?? undefined, now),
180-
new GitCommitIdentity('You', user?.email ?? undefined, now),
181-
'Uncommitted changes',
182-
[previousSha],
183-
'Uncommitted changes',
184-
{ file: file, files: [file] },
185-
undefined,
186-
[],
187-
),
167+
createUncommittedChangesCommit(container, this.repoPath, uncommitted, user, {
168+
files: { file: file, files: [file] },
169+
parents: [previousSha],
170+
}),
188171
);
189172

190173
// Decrements the date to guarantee the staged entry (if exists) will be sorted after the working entry (most recent first)
@@ -203,19 +186,10 @@ export class GitStatusFile implements GitFile {
203186
true,
204187
);
205188
commits.push(
206-
new GitCommit(
207-
container,
208-
this.repoPath,
209-
uncommittedStaged,
210-
new GitCommitIdentity('You', user?.email ?? undefined, now),
211-
new GitCommitIdentity('You', user?.email ?? undefined, now),
212-
'Uncommitted changes',
213-
['HEAD'],
214-
'Uncommitted changes',
215-
{ file: file, files: [file] },
216-
undefined,
217-
[],
218-
),
189+
createUncommittedChangesCommit(container, this.repoPath, uncommittedStaged, user, {
190+
files: { file: file, files: [file] },
191+
parents: ['HEAD'],
192+
}),
219193
);
220194
}
221195

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import type { Container } from '../../../container';
2+
import type { GitCommitStats } from '../../models/commit';
3+
import { GitCommit, GitCommitIdentity } from '../../models/commit';
4+
import type { GitFileChange } from '../../models/fileChange';
5+
import { uncommittedStaged } from '../../models/revision';
6+
import type { GitUser } from '../../models/user';
7+
8+
export function createUncommittedChangesCommit(
9+
container: Container,
10+
repoPath: string,
11+
sha: string,
12+
user: GitUser | undefined,
13+
options?: {
14+
files?: GitFileChange | GitFileChange[] | { file?: GitFileChange; files?: GitFileChange[] } | undefined;
15+
parents?: string[];
16+
stats?: GitCommitStats;
17+
},
18+
): GitCommit {
19+
const now = new Date();
20+
return new GitCommit(
21+
container,
22+
repoPath,
23+
sha,
24+
new GitCommitIdentity('You', user?.email ?? undefined, now),
25+
new GitCommitIdentity('You', user?.email ?? undefined, now),
26+
'Uncommitted changes',
27+
options?.parents ?? (sha === uncommittedStaged ? ['HEAD'] : []),
28+
'Uncommitted changes',
29+
options?.files,
30+
options?.stats,
31+
[],
32+
);
33+
}

src/plus/integrations/providers/github/sub-providers/commits.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type { GitRevisionRange } from '../../../../../git/models/revision';
1515
import { deletedOrMissing } from '../../../../../git/models/revision';
1616
import type { GitUser } from '../../../../../git/models/user';
1717
import { parseSearchQuery } from '../../../../../git/search';
18+
import { createUncommittedChangesCommit } from '../../../../../git/utils/-webview/commit.utils';
1819
import { createRevisionRange, isUncommitted } from '../../../../../git/utils/revision.utils';
1920
import { log } from '../../../../../system/decorators/log';
2021
import { filterMap, first, last, some } from '../../../../../system/iterable';
@@ -45,6 +46,15 @@ export class CommitsGitSubProvider implements GitCommitsSubProvider {
4546
const scope = getLogScope();
4647

4748
try {
49+
if (isUncommitted(rev, true)) {
50+
return createUncommittedChangesCommit(
51+
this.container,
52+
repoPath,
53+
rev,
54+
await this.provider.config.getCurrentUser(repoPath),
55+
);
56+
}
57+
4858
const { metadata, github, session } = await this.provider.ensureRepositoryContext(repoPath);
4959

5060
const commit = await github.getCommit(

0 commit comments

Comments
 (0)