Fix searching for full SHA-256 commit hashes in Git graph (#63371)

# Objective

Search in the Git graph does not support full commit hashes in SHA-256
formatted repos, while SHA-1 formatted repos work fine.

## Solution

Use existing constants in the `git` crate instead of hardcoded values
when checking for a commit hash query.

## Testing

Added a regression test for valid SHA-1 and SHA-256 commit hash lengths,
plus rejection of hashes longer than the max length.

## Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [ ] Unsafe blocks (if any) have justifying comments
- [x] The content adheres to Zed's UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

## Showcase

<details>
  <summary>Click to view showcase</summary>

The screenshots below show the commit that is being searched for open in
the Git graph.

Before:
<img width="1153" height="536" alt="before"
src="https://github.com/user-attachments/assets/e47c4523-a046-4c47-ac75-cd00845b968f"
/>

After:
<img width="1153" height="536" alt="after"
src="https://github.com/user-attachments/assets/72eeaa16-d0ec-48cb-8ca2-c2bb26f02a10"
/>

</details>

---

Release Notes:

- Fixed searching for full SHA-256 commit hashes in the Git graph.
This commit is contained in:
Albert Bogusz authored and GitHub committed 2026-08-29 12:11:25 +00:00
1 parent 88483df921
commit 432c18bcb9
1 file changed
+22 -2
+22 -2
View File
@@ -3,7 +3,7 @@ use crate::stash::GitStash;
use crate::status::{
DiffTreeType, FileStatus, GitStatus, StatusCode, TrackedStatus, TreeDiff, TreeDiffStatus,
};
use crate::{Oid, RunHook, SHORT_SHA_LENGTH};
use crate::{Oid, RunHook, SHA256_HEX_LENGTH, SHORT_SHA_LENGTH};
use anyhow::{Context as _, Result, anyhow, bail};
use async_channel::Sender;
use collections::HashMap;
@@ -764,7 +764,7 @@ pub struct SearchCommitArgs {
pub fn commit_hash_search_query(query: &str) -> Option<&str> {
let query = query.trim();
(7..=40)
(SHORT_SHA_LENGTH..=SHA256_HEX_LENGTH)
.contains(&query.len())
.then_some(query)
.filter(|query| query.bytes().all(|byte| byte.is_ascii_hexdigit()))
@@ -4273,6 +4273,26 @@ mod tests {
use super::*;
use gpui::TestAppContext;
#[test]
fn test_commit_hash_search_query_accepts_sha1_and_sha256_hashes() {
assert_eq!(
commit_hash_search_query("0123456789abcdef0123456789abcdef01234567"),
Some("0123456789abcdef0123456789abcdef01234567")
);
assert_eq!(
commit_hash_search_query(
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
),
Some("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")
);
assert_eq!(
commit_hash_search_query(
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0"
),
None
);
}
fn disable_git_global_config() {
unsafe {
std::env::set_var("GIT_CONFIG_GLOBAL", "");