diff --git a/src/git/models/stashCommit.ts b/src/git/models/stashCommit.ts index c4eca07..0335533 100644 --- a/src/git/models/stashCommit.ts +++ b/src/git/models/stashCommit.ts @@ -2,6 +2,9 @@ import { GitCommitType } from './commit'; import { GitFile } from './file'; import { GitLogCommit } from './logCommit'; +import { memoize } from '../../system'; + +const stashNumberRegex = /stash@{(\d+)}/; export class GitStashCommit extends GitLogCommit { static is(commit: any): commit is GitStashCommit { @@ -27,6 +30,14 @@ export class GitStashCommit extends GitLogCommit { super(type, repoPath, sha, 'You', undefined, authorDate, committedDate, message, fileName, files); } + @memoize() + get number() { + const match = stashNumberRegex.exec(this.stashName); + if (match == null) return undefined; + + return match[1]; + } + get shortSha() { return this.stashName; } diff --git a/src/quickpicks/gitQuickPicks.ts b/src/quickpicks/gitQuickPicks.ts index 2a1b72e..600a4cb 100644 --- a/src/quickpicks/gitQuickPicks.ts +++ b/src/quickpicks/gitQuickPicks.ts @@ -159,16 +159,31 @@ export namespace CommitQuickPickItem { options: { compact?: boolean; icon?: boolean; match?: string } = {} ) { if (GitStashCommit.is(commit)) { + const number = commit.number === undefined ? '' : `${commit.number}: `; + + if (options.compact) { + const item: CommitQuickPickItem = { + label: `${number}${commit.getShortMessage()}`, + description: `${commit.formattedDate}${Strings.pad( + GlyphChars.Dot, + 2, + 2 + )}${commit.getFormattedDiffStatus({ compact: true })}`, + picked: picked, + item: commit + }; + + return item; + } + const item: CommitQuickPickItem = { - label: commit.getShortMessage(), + label: `${number}${commit.getShortMessage()}`, description: '', - detail: `${GlyphChars.Space.repeat(2)}${commit.stashName || commit.shortSha}${Strings.pad( + detail: `${GlyphChars.Space.repeat(2)}${commit.formattedDate}${Strings.pad( GlyphChars.Dot, 2, 2 - )}${commit.formattedDate}${Strings.pad(GlyphChars.Dot, 2, 2)}${commit.getFormattedDiffStatus({ - compact: true - })}`, + )}${commit.getFormattedDiffStatus({ compact: true })}`, picked: picked, item: commit };