diff --git a/package.json b/package.json index 1f0f953642d25..5688426abf75c 100644 --- a/package.json +++ b/package.json @@ -1743,6 +1743,13 @@ "title": "Commits View", "order": 110, "properties": { + "gitlens.views.commits.showStashes": { + "type": "boolean", + "default": true, + "markdownDescription": "Specifies whether to show stashes in the _Commits_ view", + "scope": "window", + "order": 9 + }, "gitlens.views.commits.showBranchComparison": { "type": [ "boolean", @@ -2192,6 +2199,13 @@ "scope": "window", "order": 90 }, + "gitlens.views.repositories.branches.showStashes": { + "type": "boolean", + "default": true, + "markdownDescription": "Specifies whether to show stashes in the _Commits_ and _Branches_ sections of the _Repositories_ view", + "scope": "window", + "order": 95 + }, "gitlens.views.repositories.branches.showBranchComparison": { "type": [ "boolean", @@ -2355,6 +2369,13 @@ "title": "Branches View", "order": 170, "properties": { + "gitlens.views.branches.showStashes": { + "type": "boolean", + "default": true, + "markdownDescription": "Specifies whether to show stashes in the _Branches_ view", + "scope": "window", + "order": 9 + }, "gitlens.views.branches.showBranchComparison": { "type": [ "boolean", @@ -2756,6 +2777,13 @@ "scope": "resource", "order": 12 }, + "gitlens.views.worktrees.showStashes": { + "type": "boolean", + "default": true, + "markdownDescription": "Specifies whether to show stashes in the _Worktrees_ view", + "scope": "window", + "order": 19 + }, "gitlens.views.worktrees.showBranchComparison": { "type": [ "boolean", @@ -3337,6 +3365,13 @@ "scope": "window", "order": 90 }, + "gitlens.views.workspaces.branches.showStashes": { + "type": "boolean", + "default": true, + "markdownDescription": "Specifies whether to show stashes in the _Cloud Workspaces_ view", + "scope": "window", + "order": 9 + }, "gitlens.views.workspaces.branches.showBranchComparison": { "type": [ "boolean", @@ -7673,6 +7708,14 @@ "command": "gitlens.views.branches.setShowBranchPullRequestOff", "title": "Hide Branch Pull Requests" }, + { + "command": "gitlens.views.branches.setShowStashesOn", + "title": "Show Stashes" + }, + { + "command": "gitlens.views.branches.setShowStashesOff", + "title": "Hide Stashes" + }, { "command": "gitlens.views.commitDetails.refresh", "title": "Refresh", @@ -7759,6 +7802,14 @@ "command": "gitlens.views.commits.setShowBranchPullRequestOff", "title": "Hide Current Branch Pull Request" }, + { + "command": "gitlens.views.commits.setShowStashesOn", + "title": "Show Stashes" + }, + { + "command": "gitlens.views.commits.setShowStashesOff", + "title": "Hide Stashes" + }, { "command": "gitlens.views.contributors.copy", "title": "Copy" @@ -8804,6 +8855,14 @@ "command": "gitlens.views.worktrees.setShowBranchPullRequestOff", "title": "Hide Branch Pull Requests" }, + { + "command": "gitlens.views.worktrees.setShowStashesOn", + "title": "Show Stashes" + }, + { + "command": "gitlens.views.worktrees.setShowStashesOff", + "title": "Hide Stashes" + }, { "command": "gitlens.enableDebugLogging", "title": "Enable Debug Logging", @@ -11267,6 +11326,14 @@ "command": "gitlens.views.branches.setShowBranchPullRequestOff", "when": "false" }, + { + "command": "gitlens.views.branches.setShowStashesOn", + "when": "false" + }, + { + "command": "gitlens.views.branches.setShowStashesOff", + "when": "false" + }, { "command": "gitlens.views.commitDetails.refresh", "when": "false" @@ -11343,6 +11410,14 @@ "command": "gitlens.views.commits.setShowBranchPullRequestOff", "when": "false" }, + { + "command": "gitlens.views.commits.setShowStashesOn", + "when": "false" + }, + { + "command": "gitlens.views.commits.setShowStashesOff", + "when": "false" + }, { "command": "gitlens.views.contributors.copy", "when": "false" @@ -12239,6 +12314,14 @@ "command": "gitlens.views.worktrees.setShowBranchPullRequestOff", "when": "false" }, + { + "command": "gitlens.views.worktrees.setShowStashesOn", + "when": "false" + }, + { + "command": "gitlens.views.worktrees.setShowStashesOff", + "when": "false" + }, { "command": "gitlens.graph.switchToEditorLayout", "when": "gitlens:enabled && config.gitlens.graph.layout != editor" @@ -13272,6 +13355,16 @@ "when": "view == gitlens.views.branches && config.gitlens.views.branches.pullRequests.enabled && config.gitlens.views.branches.pullRequests.showForBranches", "group": "5_gitlens@2" }, + { + "command": "gitlens.views.branches.setShowStashesOn", + "when": "view == gitlens.views.branches && !config.gitlens.views.branches.showStashes", + "group": "5_gitlens@11" + }, + { + "command": "gitlens.views.branches.setShowStashesOff", + "when": "view == gitlens.views.branches && config.gitlens.views.branches.showStashes", + "group": "5_gitlens@11" + }, { "command": "gitlens.pushRepositories", "when": "gitlens:repos:withRemotes && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && view == gitlens.views.commits", @@ -13380,7 +13473,17 @@ { "command": "gitlens.views.commits.setShowBranchPullRequestOff", "when": "view == gitlens.views.commits && config.gitlens.views.commits.pullRequests.enabled && config.gitlens.views.commits.pullRequests.showForBranches", - "group": "5_gitlens@4" + "group": "5_gitlens@3" + }, + { + "command": "gitlens.views.commits.setShowStashesOn", + "when": "view == gitlens.views.commits && !config.gitlens.views.commits.showStashes", + "group": "5_gitlens@11" + }, + { + "command": "gitlens.views.commits.setShowStashesOff", + "when": "view == gitlens.views.commits && config.gitlens.views.commits.showStashes", + "group": "5_gitlens@11" }, { "command": "gitlens.showGraph", @@ -14332,15 +14435,25 @@ "when": "view == gitlens.views.worktrees && config.gitlens.views.worktrees.pullRequests.enabled && config.gitlens.views.worktrees.pullRequests.showForBranches", "group": "5_gitlens@2" }, + { + "command": "gitlens.views.worktrees.setShowStashesOn", + "when": "view == gitlens.views.worktrees && !config.gitlens.views.worktrees.showStashes", + "group": "5_gitlens@11" + }, + { + "command": "gitlens.views.worktrees.setShowStashesOff", + "when": "view == gitlens.views.worktrees && config.gitlens.views.worktrees.showStashes", + "group": "5_gitlens@11" + }, { "command": "gitlens.views.setShowRelativeDateMarkersOn", "when": "view =~ /^gitlens\\.views\\.(branches|commits|contributors|fileHistory|lineHistory|remotes|repositories|tags|worktrees)/ && !config.gitlens.views.showRelativeDateMarkers", - "group": "5_gitlens@3" + "group": "5_gitlens@10" }, { "command": "gitlens.views.setShowRelativeDateMarkersOff", "when": "view =~ /^gitlens\\.views\\.(branches|commits|contributors|fileHistory|lineHistory|remotes|repositories|tags|worktrees)/ && config.gitlens.views.showRelativeDateMarkers", - "group": "5_gitlens@3" + "group": "5_gitlens@10" }, { "submenu": "gitlens/graph/configuration", @@ -17799,12 +17912,12 @@ { "command": "gitlens.views.setShowRelativeDateMarkersOn", "when": "view == gitlens.views.scm.grouped && gitlens:views:scm:grouped:view =~ /(branches|commits|contributors|remotes|repositories|tags|worktrees)/ && !config.gitlens.views.showRelativeDateMarkers", - "group": "5_gitlens@3" + "group": "5_gitlens@10" }, { "command": "gitlens.views.setShowRelativeDateMarkersOff", "when": "view == gitlens.views.scm.grouped && gitlens:views:scm:grouped:view =~ /(branches|commits|contributors|remotes|repositories|tags|worktrees)/ && config.gitlens.views.showRelativeDateMarkers", - "group": "5_gitlens@3" + "group": "5_gitlens@10" }, { "command": "gitlens.views.branches.setLayoutToList", @@ -17861,6 +17974,16 @@ "when": "view == gitlens.views.scm.grouped && gitlens:views:scm:grouped:view == branches && config.gitlens.views.branches.pullRequests.enabled && config.gitlens.views.branches.pullRequests.showForBranches", "group": "5_gitlens@2" }, + { + "command": "gitlens.views.branches.setShowStashesOn", + "when": "view == gitlens.views.scm.grouped && gitlens:views:scm:grouped:view == branches && !config.gitlens.views.branches.showStashes", + "group": "5_gitlens@11" + }, + { + "command": "gitlens.views.branches.setShowStashesOff", + "when": "view == gitlens.views.scm.grouped && gitlens:views:scm:grouped:view == branches && config.gitlens.views.branches.showStashes", + "group": "5_gitlens@11" + }, { "command": "gitlens.showSettingsPage!branches-view", "when": "view == gitlens.views.scm.grouped && gitlens:views:scm:grouped:view == branches", @@ -17919,7 +18042,17 @@ { "command": "gitlens.views.commits.setShowBranchPullRequestOff", "when": "view == gitlens.views.scm.grouped && gitlens:views:scm:grouped:view == commits && config.gitlens.views.commits.pullRequests.enabled && config.gitlens.views.commits.pullRequests.showForBranches", - "group": "5_gitlens@4" + "group": "5_gitlens@3" + }, + { + "command": "gitlens.views.commits.setShowStashesOn", + "when": "view == gitlens.views.scm.grouped && gitlens:views:scm:grouped:view == commits && !config.gitlens.views.commits.showStashes", + "group": "5_gitlens@11" + }, + { + "command": "gitlens.views.commits.setShowStashesOff", + "when": "view == gitlens.views.scm.grouped && gitlens:views:scm:grouped:view == commits && config.gitlens.views.commits.showStashes", + "group": "5_gitlens@11" }, { "command": "gitlens.showSettingsPage!commits-view", @@ -18241,6 +18374,16 @@ "when": "view == gitlens.views.scm.grouped && gitlens:views:scm:grouped:view == worktrees && config.gitlens.views.worktrees.pullRequests.enabled && config.gitlens.views.worktrees.pullRequests.showForBranches", "group": "5_gitlens@2" }, + { + "command": "gitlens.views.worktrees.setShowStashesOn", + "when": "view == gitlens.views.scm.grouped && gitlens:views:scm:grouped:view == worktrees && !config.gitlens.views.worktrees.showStashes", + "group": "5_gitlens@11" + }, + { + "command": "gitlens.views.worktrees.setShowStashesOff", + "when": "view == gitlens.views.scm.grouped && gitlens:views:scm:grouped:view == worktrees && config.gitlens.views.worktrees.showStashes", + "group": "5_gitlens@11" + }, { "command": "gitlens.showSettingsPage!worktrees-view", "when": "view == gitlens.views.scm.grouped && gitlens:views:scm:grouped:view == worktrees", diff --git a/src/config.ts b/src/config.ts index e30c6b95c9be2..e2259e1b08e33 100644 --- a/src/config.ts +++ b/src/config.ts @@ -700,6 +700,7 @@ export interface BranchesViewConfig { }; readonly reveal: boolean; readonly showBranchComparison: false | Extract; + readonly showStashes: boolean; } export interface CommitsViewConfig { @@ -713,6 +714,7 @@ export interface CommitsViewConfig { }; readonly reveal: boolean; readonly showBranchComparison: false | ViewShowBranchComparison; + readonly showStashes: boolean; } export interface CommitDetailsViewConfig { @@ -806,6 +808,7 @@ export interface RepositoriesViewConfig { readonly branches: { readonly layout: ViewBranchesLayout; readonly showBranchComparison: false | Extract; + readonly showStashes: boolean; }; readonly compact: boolean; readonly files: ViewsFilesConfig; @@ -860,6 +863,7 @@ export interface WorktreesViewConfig { }; readonly reveal: boolean; readonly showBranchComparison: false | Extract; + readonly showStashes: boolean; } export interface WorkspacesViewConfig { @@ -867,6 +871,7 @@ export interface WorkspacesViewConfig { readonly branches: { readonly layout: ViewBranchesLayout; readonly showBranchComparison: false | Extract; + readonly showStashes: boolean; }; readonly compact: boolean; readonly files: ViewsFilesConfig; diff --git a/src/constants.commands.ts b/src/constants.commands.ts index 8207aeedcb384..fe6e5d08e1f8c 100644 --- a/src/constants.commands.ts +++ b/src/constants.commands.ts @@ -337,7 +337,8 @@ export type TreeViewCommands = `gitlens.views.${ | `setFilesLayoutTo${'Auto' | 'List' | 'Tree'}` | `setShowAvatars${'On' | 'Off'}` | `setShowBranchComparison${'On' | 'Off'}` - | `setShowBranchPullRequest${'On' | 'Off'}`}` + | `setShowBranchPullRequest${'On' | 'Off'}` + | `setShowStashes${'On' | 'Off'}`}` | `commits.${ | 'copy' | 'refresh' @@ -346,7 +347,8 @@ export type TreeViewCommands = `gitlens.views.${ | `setShowAvatars${'On' | 'Off'}` | `setShowBranchComparison${'On' | 'Off'}` | `setShowBranchPullRequest${'On' | 'Off'}` - | `setShowMergeCommits${'On' | 'Off'}`}` + | `setShowMergeCommits${'On' | 'Off'}` + | `setShowStashes${'On' | 'Off'}`}` | `contributors.${ | 'copy' | 'refresh' @@ -451,7 +453,8 @@ export type TreeViewCommands = `gitlens.views.${ | `setFilesLayoutTo${'Auto' | 'List' | 'Tree'}` | `setShowAvatars${'On' | 'Off'}` | `setShowBranchComparison${'On' | 'Off'}` - | `setShowBranchPullRequest${'On' | 'Off'}`}`}`; + | `setShowBranchPullRequest${'On' | 'Off'}` + | `setShowStashes${'On' | 'Off'}`}`}`; type ExtractSuffix = U extends `${Prefix}${infer V}` ? V : never; type FilterCommands = U extends `${Prefix}${infer V}` ? `${Prefix}${V}` : never; diff --git a/src/env/node/git/git.ts b/src/env/node/git/git.ts index f109e990e0532..eb9f6f5a2da73 100644 --- a/src/env/node/git/git.ts +++ b/src/env/node/git/git.ts @@ -1591,7 +1591,7 @@ export class Git { async rev_list( repoPath: string, ref: string, - options?: { all?: boolean; maxParents?: number }, + options?: { all?: boolean; maxParents?: number; since?: string }, ): Promise { const params = ['rev-list']; if (options?.all) { @@ -1602,6 +1602,10 @@ export class Git { params.push(`--max-parents=${options.maxParents}`); } + if (options?.since) { + params.push(`--since="${options.since}"`, '--date-order'); + } + const rawData = await this.git( { cwd: repoPath, errors: GitErrorHandling.Ignore }, ...params, diff --git a/src/env/node/git/localGitProvider.ts b/src/env/node/git/localGitProvider.ts index ed099e9b94008..7a744a2adda28 100644 --- a/src/env/node/git/localGitProvider.ts +++ b/src/env/node/git/localGitProvider.ts @@ -188,7 +188,17 @@ import { countStringLength, filterMap } from '../../../system/array'; import { gate } from '../../../system/decorators/gate'; import { debug, log } from '../../../system/decorators/log'; import { debounce } from '../../../system/function'; -import { filterMap as filterMapIterable, find, first, join, last, map, skip, some } from '../../../system/iterable'; +import { + filterMap as filterMapIterable, + find, + first, + join, + last, + map, + min, + skip, + some, +} from '../../../system/iterable'; import { Logger } from '../../../system/logger'; import type { LogScope } from '../../../system/logger.scope'; import { getLogScope, setLogScopeExit } from '../../../system/logger.scope'; @@ -2398,7 +2408,7 @@ export class LocalGitProvider implements GitProvider, Disposable { const [refResult, stashResult, branchesResult, remotesResult, currentUserResult, worktreesResult] = await Promise.allSettled([ this.git.log(repoPath, undefined, ...refParser.arguments, '-n1', options?.ref ?? 'HEAD'), - this.getStash(repoPath), + this.getStash(repoPath, { reachableFrom: options?.ref }), this.getBranches(repoPath), this.getRemotes(repoPath), this.getCurrentUser(repoPath), @@ -3658,11 +3668,11 @@ export class LocalGitProvider implements GitProvider, Disposable { merges?: boolean | 'first-parent'; ordering?: 'date' | 'author-date' | 'topo' | null; ref?: string; - status?: null | 'name-status' | 'numstat' | 'stat'; since?: number | string; + stashes?: boolean | Map; + status?: null | 'name-status' | 'numstat' | 'stat'; until?: number | string; extraArgs?: string[]; - stdin?: string; }, ): Promise { const scope = getLogScope(); @@ -3727,61 +3737,56 @@ export class LocalGitProvider implements GitProvider, Disposable { args.push(`-n${limit + 1}`); } + let ref = options?.ref; + + let stashes: Map | undefined; + let stdin: string | undefined; + + if (options?.stashes) { + if (typeof options.stashes === 'boolean') { + // TODO@eamodio this is insanity -- there *HAS* to be a better way to get git log to return stashes + const stash = await this.getStash(repoPath, { reachableFrom: options?.ref }); + stashes = new Map(stash?.commits); + if (stash?.commits.size) { + stdin = ''; + for (const commit of stash.commits.values()) { + stdin += `${commit.sha.substring(0, 9)}\n`; + // Include the stash's 2nd (index files) and 3rd (untracked files) parents + for (const p of skip(commit.parents, 1)) { + stashes.set(p, commit); + stdin += `${p.substring(0, 9)}\n`; + } + } + } + ref ??= 'HEAD'; + } else { + stashes = options.stashes; + stdin = join( + map(stashes.values(), c => c.sha.substring(0, 9)), + '\n', + ); + ref ??= 'HEAD'; + } + } + const data = await this.git.log( repoPath, - { configs: gitLogDefaultConfigsWithFiles, ref: options?.ref, stdin: options?.stdin }, + { configs: gitLogDefaultConfigsWithFiles, ref: ref, stdin: stdin }, ...args, ); - // const parser = GitLogParser.defaultParser; - - // const data = await this.git.log2(repoPath, options?.ref, { - // ...options, - // // args: parser.arguments, - // limit: limit, - // merges: options?.merges == null ? true : options.merges, - // ordering: options?.ordering ?? configuration.get('advanced.commitOrdering'), - // similarityThreshold: configuration.get('advanced.similarityThreshold'), - // }); - - // const commits = []; - // const entries = parser.parse(data); - // for (const entry of entries) { - // commits.push( - // new GitCommit2( - // repoPath, - // entry.sha, - // new GitCommitIdentity( - // entry.author, - // entry.authorEmail, - // new Date((entry.authorDate as any) * 1000), - // ), - // new GitCommitIdentity( - // entry.committer, - // entry.committerEmail, - // new Date((entry.committerDate as any) * 1000), - // ), - // entry.message.split('\n', 1)[0], - // entry.parents.split(' '), - // entry.message, - // entry.files.map(f => new GitFileChange(repoPath, f.path, f.status as any, f.originalPath)), - // [], - // ), - // ); - // } - const log = parseGitLog( this.container, data, LogType.Log, repoPath, undefined, - options?.ref, + ref, await this.getCurrentUser(repoPath), limit, false, undefined, - undefined, + stashes, undefined, hasMoreOverride, ); @@ -4993,7 +4998,7 @@ export class LocalGitProvider implements GitProvider, Disposable { @gate() @log() - async getStash(repoPath: string | undefined): Promise { + async getStash(repoPath: string | undefined, options?: { reachableFrom?: string }): Promise { if (repoPath == null) return undefined; let stash = this.useCaching ? this._stashesCache.get(repoPath) : undefined; @@ -5072,6 +5077,27 @@ export class LocalGitProvider implements GitProvider, Disposable { } } + // Return only reachable stashes from the given ref + if (options?.reachableFrom && stash != null) { + const oldestStashDate = new Date(min(stash.commits.values(), c => c.date.getTime())).toISOString(); + + const ancestors = await this.git.rev_list(repoPath, options.reachableFrom, { since: oldestStashDate }); + if (ancestors?.length && (ancestors.length !== 1 || ancestors[0])) { + const reachable = new Set(ancestors); + + if (reachable.size) { + for (const [sha, commit] of stash.commits) { + if (commit.parents.some(p => p === options.reachableFrom || reachable.has(p))) { + continue; + } + stash.commits.delete(sha); + } + } else { + stash.commits.clear(); + } + } + } + return stash ?? undefined; } diff --git a/src/git/gitProviderService.ts b/src/git/gitProviderService.ts index aeb41768e11f0..b9bbe56687749 100644 --- a/src/git/gitProviderService.ts +++ b/src/git/gitProviderService.ts @@ -2029,6 +2029,7 @@ export class GitProviderService implements Disposable { ordering?: 'date' | 'author-date' | 'topo' | null; ref?: string; since?: string; + stashes?: boolean; }, ): Promise { const { provider, path } = this.getProvider(repoPath); diff --git a/src/views/branchesView.ts b/src/views/branchesView.ts index 886601096349e..f95bec7da55e5 100644 --- a/src/views/branchesView.ts +++ b/src/views/branchesView.ts @@ -178,6 +178,8 @@ export class BranchesView extends ViewBase<'branches', BranchesViewNode, Branche () => this.setShowBranchPullRequest(false), this, ), + registerViewCommand(this.getQualifiedCommand('setShowStashesOn'), () => this.setShowStashes(true), this), + registerViewCommand(this.getQualifiedCommand('setShowStashesOff'), () => this.setShowStashes(false), this), ]; } @@ -353,4 +355,8 @@ export class BranchesView extends ViewBase<'branches', BranchesViewNode, Branche await configuration.updateEffective(`views.${this.configKey}.pullRequests.showForBranches` as const, enabled); await configuration.updateEffective(`views.${this.configKey}.pullRequests.enabled` as const, enabled); } + + private setShowStashes(enabled: boolean) { + return configuration.updateEffective(`views.${this.configKey}.showStashes` as const, enabled); + } } diff --git a/src/views/commitsView.ts b/src/views/commitsView.ts index 5f09b5a026290..da351a497eed1 100644 --- a/src/views/commitsView.ts +++ b/src/views/commitsView.ts @@ -57,6 +57,7 @@ export class CommitsRepositoryNode extends RepositoryFolderNode this.setShowBranchPullRequest(false), this, ), + registerViewCommand(this.getQualifiedCommand('setShowStashesOn'), () => this.setShowStashes(true), this), + registerViewCommand(this.getQualifiedCommand('setShowStashesOff'), () => this.setShowStashes(false), this), ]; } @@ -509,4 +512,8 @@ export class CommitsView extends ViewBase<'commits', CommitsViewNode, CommitsVie await configuration.updateEffective(`views.${this.configKey}.pullRequests.showForBranches` as const, enabled); await configuration.updateEffective(`views.${this.configKey}.pullRequests.enabled` as const, enabled); } + + private setShowStashes(enabled: boolean) { + return configuration.updateEffective(`views.${this.configKey}.showStashes` as const, enabled); + } } diff --git a/src/views/nodes/branchNode.ts b/src/views/nodes/branchNode.ts index 1a37e583a8569..058d711a0752b 100644 --- a/src/views/nodes/branchNode.ts +++ b/src/views/nodes/branchNode.ts @@ -9,6 +9,7 @@ import type { GitUri } from '../../git/gitUri'; import { unknownGitUri } from '../../git/gitUri'; import type { GitBranch } from '../../git/models/branch'; import { getTargetBranchName } from '../../git/models/branch'; +import { isStash } from '../../git/models/commit'; import type { GitLog } from '../../git/models/log'; import type { PullRequest, PullRequestState } from '../../git/models/pullRequest'; import type { GitBranchReference } from '../../git/models/reference'; @@ -44,6 +45,7 @@ import { insertDateMarkers } from './helpers'; import { MergeStatusNode } from './mergeStatusNode'; import { PullRequestNode } from './pullRequestNode'; import { RebaseStatusNode } from './rebaseStatusNode'; +import { StashNode } from './stashNode'; type State = { pullRequest: PullRequest | null | undefined; @@ -57,6 +59,7 @@ type Options = { showComparison: false | ViewShowBranchComparison; showStatusDecorationOnly: boolean; showMergeCommits?: boolean; + showStashes: boolean; showStatus: boolean; showTracking: boolean; authors?: GitUser[]; @@ -92,6 +95,7 @@ export class BranchNode limitCommits: false, showAsCommits: false, showComparison: false, + showStashes: false, // Only show status decorations when the node is displayed as a root showStatusDecorationOnly: this.root, // Don't show merge/rebase status info the node is displayed as a root @@ -386,17 +390,17 @@ export class BranchNode children.push( ...insertDateMarkers( - map( - log.commits.values(), - c => - new CommitNode( - this.view, - this, - c, - unpublishedCommits?.has(c.ref), - branch, - getBranchAndTagTips, - ), + map(log.commits.values(), c => + isStash(c) + ? new StashNode(this.view, this, c, { icon: true }) + : new CommitNode( + this.view, + this, + c, + unpublishedCommits?.has(c.ref), + branch, + getBranchAndTagTips, + ), ), this, ), @@ -510,6 +514,7 @@ export class BranchNode ref: this.ref.ref, authors: this.options?.authors, merges: this.options?.showMergeCommits, + stashes: this.options?.showStashes, }); } diff --git a/src/views/nodes/branchesNode.ts b/src/views/nodes/branchesNode.ts index 8034455e9becb..032d869142d61 100644 --- a/src/views/nodes/branchesNode.ts +++ b/src/views/nodes/branchesNode.ts @@ -62,6 +62,7 @@ export class BranchesNode extends CacheableChildrenViewNode<'branches', ViewsWit this.view.type === 'repositories' ? this.view.config.branches.showBranchComparison : this.view.config.showBranchComparison, + showStashes: this.view.config.showStashes, }, ), ); diff --git a/src/views/nodes/remoteNode.ts b/src/views/nodes/remoteNode.ts index cbf0f1842a394..fa4e819817e6e 100644 --- a/src/views/nodes/remoteNode.ts +++ b/src/views/nodes/remoteNode.ts @@ -52,6 +52,7 @@ export class RemoteNode extends ViewNode<'remote', ViewsWithRemotes> { b => new BranchNode(GitUri.fromRepoPath(this.uri.repoPath!, b.ref), this.view, this, this.repo, b, false, { showComparison: false, + showStashes: false, showTracking: false, }), ); diff --git a/src/views/nodes/repositoryNode.ts b/src/views/nodes/repositoryNode.ts index 93cceb98070f8..94c87865f2936 100644 --- a/src/views/nodes/repositoryNode.ts +++ b/src/views/nodes/repositoryNode.ts @@ -159,6 +159,7 @@ export class RepositoryNode extends SubscribeableViewNode<'repository', ViewsWit new BranchNode(this.uri, this.view, this, this.repo, branch, true, { showAsCommits: true, showComparison: false, + showStashes: this.view.config.branches.showStashes, showStatusDecorationOnly: true, showStatus: false, showTracking: false, diff --git a/src/views/worktreesView.ts b/src/views/worktreesView.ts index 5160d7d71c57d..eecf923bd5b1b 100644 --- a/src/views/worktreesView.ts +++ b/src/views/worktreesView.ts @@ -175,6 +175,8 @@ export class WorktreesView extends ViewBase<'worktrees', WorktreesViewNode, Work () => this.setShowBranchPullRequest(false), this, ), + registerViewCommand(this.getQualifiedCommand('setShowStashesOn'), () => this.setShowStashes(true), this), + registerViewCommand(this.getQualifiedCommand('setShowStashesOff'), () => this.setShowStashes(false), this), ]; } @@ -280,4 +282,8 @@ export class WorktreesView extends ViewBase<'worktrees', WorktreesViewNode, Work await configuration.updateEffective(`views.${this.configKey}.pullRequests.showForBranches` as const, enabled); await configuration.updateEffective(`views.${this.configKey}.pullRequests.enabled` as const, enabled); } + + private setShowStashes(enabled: boolean) { + return configuration.updateEffective(`views.${this.configKey}.showStashes` as const, enabled); + } }