Skip to content

Always show commit SHA in tree - #8840

Merged
Alex Ross (alexr00) merged 7 commits into
microsoft:mainfrom
jameswilmiller:show-commit-sha-in-tree
Sep 1, 2026
Merged

Always show commit SHA in tree#8840
Alex Ross (alexr00) merged 7 commits into
microsoft:mainfrom
jameswilmiller:show-commit-sha-in-tree

Conversation

@jameswilmiller

@jameswilmiller James Miller (jameswilmiller) commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Fixes #8701

I wasn't sure whether community contributions were being accepted but I took the liberty of making the PR.

Summary:

Initially pull request added a new setting to display abbreviated commit SHAs in the pull request commits tree.

When enabled, commit descriptions are shown in the following format:

49334c4 · 2 days ago

The setting defaults to disabled, so the existing behaviour remains unchanged.

PR was modified upon review to make SHA always show in tree, and the setting was removed.

Changes:

  • Added the githubPullRequests.showCommitShaInTree setting.
  • Added localized text for the setting.
  • Displayed the first seven characters of the commit SHA when the setting is enabled.
  • Preserved the relative commit date when available.
  • Refreshed the commits tree immediately when the setting changes.

Testing:

manually verified that:

  • The setting is disabled by default.
  • Enabling the setting displays the abbreviated commit SHA.
  • Disabling the setting removes the SHA.
  • The commits tree updates without reloading the window.
  • Commits with a date display · .
  • Commits without a date display only the short SHA when enabled.
  • Existing commit-tree functionality continues to work.

No automated tests were added ( I wasn't sure whether this was required but I am happy to write some if needed ).

I have attached screenshots below,

Screenshots

Setting:
image

Disabled Setting:
image

Disabled Setting with no date:
image

Enabled Setting:
image

Enabled Setting with no date:
image

Copilot AI lite review requested due to automatic review settings July 13, 2026 16:25
@jameswilmiller

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Copilot AI review requested due to automatic review settings August 19, 2026 03:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Suppressed comments (4)

src/view/treeNodes/commitNode.ts:51

  • The description is computed once in the constructor, so toggling showCommitShaInTree may not update existing CommitNode instances even if the parent refreshes. To ensure the UI reflects the current setting, compute/update description inside getTreeItem() (or recompute on refresh) rather than only in the constructor.
		this.description = this._getDescription();
	}

	private _getDescription(): string | undefined {
		const date = this.commit.commit.author?.date ? dateFromNow(this.commit.commit.author.date) : undefined;
		if (!vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<boolean>(SHOW_COMMIT_SHA_IN_TREE, false)) {
			return date;
		}
		const shortSha = this.commit.sha.substring(0, 7);
		return date ? `${shortSha} · ${date}` : shortSha;

	}

src/view/treeNodes/commitsCategoryNode.ts:48

  • Use the standard capitalization 'SHA' instead of 'Sha' in the log message.
				Logger.appendLine(`Commit Sha display setting has changed, refreshing Commits node`, PR_TREE);

package.nls.json:193

  • This description string is missing a trailing period, which is inconsistent with nearby setting descriptions.
	"githubPullRequests.showCommitShaInTree.description": "Shows the abbreviated commit SHA in the tree view",

src/view/treeNodes/commitNode.ts:41

  • The leading underscore is typically redundant on private methods in TypeScript and can be inconsistent with common conventions. Consider renaming to getDescription() (or computeDescription()) for clarity and consistency.
	private _getDescription(): string | undefined {

Copilot AI review requested due to automatic review settings August 20, 2026 04:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Suppressed comments (2)

src/view/treeNodes/commitNode.ts:46

  • The new setting-driven formatting logic in _getDescription is not covered by automated tests. Since the repo already has unit tests for tree nodes under src/test/view/treeNodes, it would be good to add a focused test verifying the description output for (1) setting disabled, (2) enabled + date, and (3) enabled + no date.
	private _getDescription(): string | undefined {
		const date = this.commit.commit.author?.date ? dateFromNow(this.commit.commit.author.date) : undefined;
		if (!vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<boolean>(SHOW_COMMIT_SHA_IN_TREE, false)) {
			return date;
		}
		const shortSha = this.commit.sha.substring(0, 7);
		return date ? `${shortSha} · ${date}` : shortSha;

src/view/treeNodes/commitNode.ts:48

  • CommitNode already stores sha on the instance (this.sha = commit.sha), but _getDescription re-reads it from this.commit.sha. Using this.sha avoids duplication and keeps the source of truth consistent.
		const shortSha = this.commit.sha.substring(0, 7);
		return date ? `${shortSha} · ${date}` : shortSha;

	}

Copilot AI review requested due to automatic review settings August 20, 2026 04:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Suppressed comments (1)

src/view/treeNodes/commitNode.ts:46

  • New config-driven description formatting is introduced here but isn’t covered by unit tests. The repo already has Mocha tests for tree nodes under src/test/view/treeNodes/ and patterns for stubbing vscode.workspace.getConfiguration (e.g. src/test/issues/stateManager.test.ts). Consider adding a CommitNode test that verifies: (1) setting disabled => description is just the relative date/undefined, (2) setting enabled + date => <shortSha> · <relativeDate>, (3) setting enabled + no date => <shortSha> (use fake timers to make dateFromNow deterministic).
		if (!vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<boolean>(SHOW_COMMIT_SHA_IN_TREE, false)) {
			return date;
		}
		const shortSha = this.sha.substring(0, 7);
		return date ? `${shortSha} · ${date}` : shortSha;

@alexr00 Alex Ross (alexr00) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! This looks good, but I'm not sure we actually need a setting for this: let's just always show the commit sha exactly as you have it. If enough folks don't like it, I'll bring back your setting.

Copilot AI review requested due to automatic review settings August 29, 2026 08:24
@jameswilmiller

James Miller (jameswilmiller) commented Aug 29, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback. I removed the setting and made commit SHAs always display in the Commits tree. I also manually verified the behavior in the Extension Development Host.

test

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread src/view/treeNodes/commitNode.ts
Copilot AI review requested due to automatic review settings August 29, 2026 08:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Suppressed comments (1)

src/view/treeNodes/commitNode.ts:44

  • The new description formatting is applied unconditionally, so commit SHAs will show even when the proposed setting is disabled (and commits without a date will now always show a SHA). This contradicts the PR description/default behavior and changes the existing UI when the setting is off.

Consider gating the SHA prefix behind a configuration check (and returning the original date-only/undefined description when disabled). Also, the setting key doesn’t appear to exist elsewhere in the repo yet (no matches for showCommitShaInTree), so this code should be resilient to the setting being absent (treat as disabled).

	private _getDescription(): string | undefined {
		const date = this.commit.commit.author?.date ? dateFromNow(this.commit.commit.author.date) : undefined;
		const shortSha = this.sha.substring(0, 7);
		return date ? `${shortSha} · ${date}` : shortSha;

Comment thread src/view/treeNodes/commitNode.ts
@jameswilmiller James Miller (jameswilmiller) changed the title Add setting to show commit SHAs in tree Always show commit SHA in tree Aug 31, 2026
@alexr00 Alex Ross (alexr00) added this to the 1.137.0 milestone Aug 31, 2026
@alexr00

Copy link
Copy Markdown
Member

/AzurePipelines run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
2 pipeline(s) were filtered out due to trigger conditions.

@alexr00
Alex Ross (alexr00) enabled auto-merge (squash) September 1, 2026 16:01
@alexr00 Alex Ross (alexr00) self-assigned this Sep 1, 2026
@alexr00
Alex Ross (alexr00) merged commit 9f1a80b into microsoft:main Sep 1, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pull Requests / Commit Message

4 participants