Skip to content

Commit 24ea659

Browse files
sergeibbbd13
authored andcommitted
Compute oldest timestamp for stashes including parent commit dates
(#4401, #4468)
1 parent ae4bf5d commit 24ea659

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
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

1818
### Fixed
1919

20+
- Fixes stashes with parent commits older than the oldest stash not being visible on branches ([#4401](https://github.com/gitkraken/vscode-gitlens/issues/4401))
2021
- Fixes editing search result in Search & Compare view failure ([#4431](https://github.com/gitkraken/vscode-gitlens/issues/4431))
2122
- Fixes search results not paging properly on the _Commit Graph_ when the first page of results is contained within the already loaded commits
2223

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export class StashGitSubProvider implements GitStashSubProvider {
166166
// Create a copy because we are going to modify it and we don't want to mutate the cache
167167
const stashes = new Map(stash.stashes);
168168

169-
const oldestStashDate = new Date(min(stash.stashes.values(), c => c.date.getTime())).toISOString();
169+
const oldestStashDate = new Date(findOldestStashTimestamp(stash.stashes.values())).toISOString();
170170

171171
const result = await this.git.exec(
172172
{ cwd: repoPath, cancellation: cancellation, errors: GitErrorHandling.Ignore },
@@ -481,3 +481,22 @@ function createStash(container: Container, s: ParsedStash, repoPath: string): Gi
481481
onRef,
482482
) as GitStashCommit;
483483
}
484+
485+
/**
486+
* Finds the oldest timestamp among stash commits and their parent commits.
487+
* This includes both the stash commit dates and all parent commit timestamps (author and committer dates).
488+
*
489+
* @param stashes - Collection of stash commits to analyze
490+
* @returns The oldest timestamp in milliseconds, or Infinity if no stashes provided
491+
*/
492+
export function findOldestStashTimestamp(stashes: Iterable<GitStashCommit>): number {
493+
return min(stashes, c => {
494+
return Math.min(
495+
c.date.getTime(),
496+
...(c.parentTimestamps
497+
?.flatMap(p => [p.authorDate, p.committerDate])
498+
.filter((x): x is number => x != null)
499+
.map(x => x * 1000) ?? []),
500+
);
501+
});
502+
}

0 commit comments

Comments
 (0)