Skip to content

Commit b39e3bf

Browse files
committed
Ensures search results files are filtered properly
1 parent d35d386 commit b39e3bf

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

src/git/models/commit.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -239,17 +239,23 @@ export class GitCommit implements GitRevisionReference {
239239
allowFilteredFiles?: boolean;
240240
include?: { stats?: boolean };
241241
}): this is GitCommitWithFullDetails {
242-
return (
243-
this.message != null &&
244-
this.fileset != null &&
245-
((options?.allowFilteredFiles && this.fileset.filtered) || !this.fileset.filtered) &&
246-
(!options?.include?.stats || this.fileset.files.some(f => f.stats != null)) &&
247-
((this.isUncommitted &&
248-
// If this is an uncommitted commit, check if we need to load the working files (if we don't have a matching etag -- only works if we are currently watching the file system for this repository)
249-
this._etagFileSystem === this.container.git.getRepository(this.repoPath)?.etagFileSystem) ||
250-
this.parents.length !== 0) &&
251-
(this.refType !== 'stash' || this._stashUntrackedFilesLoaded)
252-
);
242+
if (this.message == null || this.fileset == null) return false;
243+
if (this.fileset.filtered && !options?.allowFilteredFiles) return false;
244+
if (this.refType === 'stash' && !this._stashUntrackedFilesLoaded && !options?.allowFilteredFiles) {
245+
return false;
246+
}
247+
if (options?.include?.stats && this.fileset.files.some(f => f.stats == null)) {
248+
return false;
249+
}
250+
// If this is an uncommitted commit, check if we need to load the working files (if we don't have a matching etag -- only works if we are currently watching the file system for this repository)
251+
if (
252+
this.isUncommitted &&
253+
(!this.parents.length ||
254+
this._etagFileSystem !== this.container.git.getRepository(this.repoPath)?.etagFileSystem)
255+
) {
256+
return false;
257+
}
258+
return true;
253259
}
254260

255261
@gate()

src/views/nodes/resultsCommitsNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,13 @@ export class ResultsCommitsNode<View extends ViewsWithCommits = ViewsWithCommits
140140
);
141141
}
142142

143-
const options = { expand: this._options.expand && log.count === 1 };
143+
const options = { allowFilteredFiles: true, expand: this._options.expand && log.count === 1 };
144144

145145
children.push(
146146
...insertDateMarkers(
147147
map(log.commits.values(), c =>
148148
isStash(c)
149-
? new StashNode(this.view, this, c, { icon: true })
149+
? new StashNode(this.view, this, c, { allowFilteredFiles: true, icon: true })
150150
: new CommitNode(this.view, this, c, undefined, undefined, getBranchAndTagTips, options),
151151
),
152152
this,

src/views/nodes/stashNode.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class StashNode extends ViewRefNode<'stash', ViewsWithStashes, GitStashRe
2121
view: ViewsWithStashes,
2222
protected override parent: ViewNode,
2323
public readonly commit: GitStashCommit,
24-
private readonly options?: { icon?: boolean },
24+
private readonly _options?: { allowFilteredFiles?: boolean; icon?: boolean },
2525
) {
2626
super('stash', commit.getGitUri(), view, parent);
2727

@@ -43,7 +43,10 @@ export class StashNode extends ViewRefNode<'stash', ViewsWithStashes, GitStashRe
4343

4444
async getChildren(): Promise<ViewNode[]> {
4545
// Ensure we have checked for untracked files (inside the getCommitsForFiles call)
46-
const commits = await this.commit.getCommitsForFiles({ include: { stats: true } });
46+
const commits = await this.commit.getCommitsForFiles({
47+
allowFilteredFiles: this._options?.allowFilteredFiles,
48+
include: { stats: true },
49+
});
4750
let children: FileNode[] = commits.map(c => new StashFileNode(this.view, this, c.file!, c as GitStashCommit));
4851

4952
if (this.view.config.files.layout !== 'list') {
@@ -76,24 +79,25 @@ export class StashNode extends ViewRefNode<'stash', ViewsWithStashes, GitStashRe
7679
dateFormat: configuration.get('defaultDateFormat'),
7780
});
7881
item.contextValue = ContextValues.Stash;
79-
if (this.options?.icon) {
82+
if (this._options?.icon) {
8083
item.iconPath = new ThemeIcon('archive');
8184
}
8285

8386
return item;
8487
}
8588

8689
override async resolveTreeItem(item: TreeItem, token: CancellationToken): Promise<TreeItem> {
87-
if (item.tooltip == null) {
88-
item.tooltip = await this.getTooltip(token);
89-
}
90+
item.tooltip ??= await this.getTooltip(token);
9091
return item;
9192
}
9293

9394
private async getTooltip(cancellation: CancellationToken) {
9495
const [remotesResult, _] = await Promise.allSettled([
9596
this.view.container.git.remotes(this.commit.repoPath).getBestRemotesWithProviders(cancellation),
96-
this.commit.ensureFullDetails({ include: { stats: true } }),
97+
this.commit.ensureFullDetails({
98+
allowFilteredFiles: this._options?.allowFilteredFiles,
99+
include: { stats: true },
100+
}),
97101
]);
98102

99103
if (cancellation.isCancellationRequested) return undefined;

0 commit comments

Comments
 (0)