Skip to content

Commit 4e0ac64

Browse files
committed
fix(git): standardise short hash length
1 parent 41559fa commit 4e0ac64

8 files changed

Lines changed: 26 additions & 17 deletions

File tree

‎src-tauri/build.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ fn main() {
2020
std::env::var("GITHUB_SHA")
2121
.ok()
2222
.filter(|v| !v.trim().is_empty())
23-
.map(|sha| sha[..8.min(sha.len())].to_string())
23+
.map(|sha| sha[..7.min(sha.len())].to_string())
2424
})
2525
.or_else(|| {
2626
std::process::Command::new("git")
27-
.args(["rev-parse", "--short", "HEAD"])
27+
.args(["rev-parse", "--short=7", "HEAD"])
2828
.output()
2929
.ok()
3030
.filter(|o| o.status.success())

‎src-tauri/src/ai/commands.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2054,7 +2054,7 @@ fn writing_context(
20542054
let commits = if include_commit_history {
20552055
String::from_utf8(git_output(
20562056
repo_path,
2057-
&["log", "--format=%h %s", &commit_range],
2057+
&["log", "--abbrev=7", "--format=%h %s", &commit_range],
20582058
MAX_GIT_METADATA_OUTPUT_BYTES,
20592059
)?)
20602060
.map_err(|_| AiError::new("gitFailed"))?

‎src-tauri/src/git/cli.rs‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2919,6 +2919,7 @@ impl GitOperationHandler for CliGitHandler {
29192919

29202920
let mut args = vec![
29212921
"log",
2922+
"--abbrev=7",
29222923
"-n",
29232924
limit.as_str(),
29242925
skip.as_str(),
@@ -3671,8 +3672,10 @@ impl GitOperationHandler for CliGitHandler {
36713672

36723673
fn stash_list(&self, request: &RepoRequest) -> GitResult<Vec<StashEntry>> {
36733674
let repo_path = Self::normalise_repo_path(&request.repo_path)?;
3674-
let output = match Self::run_git(&["stash", "list", "--format=%gd|%h|%s"], Some(&repo_path))
3675-
{
3675+
let output = match Self::run_git(
3676+
&["stash", "list", "--abbrev=7", "--format=%gd|%h|%s"],
3677+
Some(&repo_path),
3678+
) {
36763679
Ok(o) => o,
36773680
Err(GitError::CommandFailed { stderr, .. }) if stderr.is_empty() => {
36783681
return Ok(Vec::new());
@@ -5649,7 +5652,7 @@ impl CliGitHandler {
56495652
}
56505653

56515654
// Fallback: resolve MERGE_HEAD to a short hash
5652-
Self::run_git(&["rev-parse", "--short", "MERGE_HEAD"], Some(repo_path))
5655+
Self::run_git(&["rev-parse", "--short=7", "MERGE_HEAD"], Some(repo_path))
56535656
.ok()
56545657
.map(|s| s.trim().to_string())
56555658
.filter(|s| !s.is_empty())
@@ -5673,7 +5676,7 @@ impl CliGitHandler {
56735676
.filter(|value| !value.is_empty())
56745677
})?;
56755678

5676-
Self::run_git(&["rev-parse", "--short", onto.as_str()], Some(repo_path))
5679+
Self::run_git(&["rev-parse", "--short=7", onto.as_str()], Some(repo_path))
56775680
.ok()
56785681
.map(|value| value.trim().to_string())
56795682
.filter(|value| !value.is_empty())
@@ -5690,7 +5693,7 @@ impl CliGitHandler {
56905693
.map(|value| value.trim().to_string())
56915694
.filter(|value| !value.is_empty())?;
56925695

5693-
Self::run_git(&["rev-parse", "--short", head.as_str()], Some(repo_path))
5696+
Self::run_git(&["rev-parse", "--short=7", head.as_str()], Some(repo_path))
56945697
.ok()
56955698
.map(|value| value.trim().to_string())
56965699
.filter(|value| !value.is_empty())
@@ -5707,7 +5710,7 @@ impl CliGitHandler {
57075710
.map(|v| v.trim().to_string())
57085711
.filter(|v| !v.is_empty())?;
57095712

5710-
Self::run_git(&["rev-parse", "--short", head.as_str()], Some(repo_path))
5713+
Self::run_git(&["rev-parse", "--short=7", head.as_str()], Some(repo_path))
57115714
.ok()
57125715
.map(|v| v.trim().to_string())
57135716
.filter(|v| !v.is_empty())
@@ -5722,7 +5725,7 @@ impl CliGitHandler {
57225725
}
57235726

57245727
let detached_head =
5725-
Self::run_git(&["rev-parse", "--short", "HEAD"], Some(repo_path)).ok()?;
5728+
Self::run_git(&["rev-parse", "--short=7", "HEAD"], Some(repo_path)).ok()?;
57265729
let trimmed_detached_head = detached_head.trim();
57275730
if trimmed_detached_head.is_empty() {
57285731
None

‎src/components/ProjectView.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,7 +1666,7 @@ export function ProjectView({
16661666
}
16671667

16681668
const confirmed = await ask(
1669-
t("ask.cherryPickCommit.message", { commit: commitHash.slice(0, 12), branch: currentBranch ?? t("labels.currentBranch") }),
1669+
t("ask.cherryPickCommit.message", { commit: commitHash.slice(0, 7), branch: currentBranch ?? t("labels.currentBranch") }),
16701670
{ title: t("ask.cherryPickCommit.title"), kind: "warning", okLabel: t("actions.cherryPick"), cancelLabel: t("actions.cancel") },
16711671
);
16721672
if (!confirmed) return;
@@ -2203,7 +2203,7 @@ export function ProjectView({
22032203
}
22042204

22052205
const confirmed = await ask(
2206-
t("ask.revertCommit.message", { commit: commitHash.slice(0, 12), branch: currentBranch ?? t("labels.currentBranch") }),
2206+
t("ask.revertCommit.message", { commit: commitHash.slice(0, 7), branch: currentBranch ?? t("labels.currentBranch") }),
22072207
{ title: t("ask.revertCommit.title"), kind: "warning", okLabel: t("actions.revert"), cancelLabel: t("actions.cancel") },
22082208
);
22092209
if (!confirmed) return;
@@ -2279,7 +2279,7 @@ export function ProjectView({
22792279
? t("ask.resetToCommit.softDescription")
22802280
: t("ask.resetToCommit.mixedDescription");
22812281
const confirmed = await ask(
2282-
t("ask.resetToCommit.message", { mode: modeLabel, commit: commitHash.slice(0, 12), description: modeDesc }),
2282+
t("ask.resetToCommit.message", { mode: modeLabel, commit: commitHash.slice(0, 7), description: modeDesc }),
22832283
{ title: t("ask.resetToCommit.title", { mode: modeLabel }), kind: "warning", okLabel: t("actions.reset"), cancelLabel: t("actions.cancel") },
22842284
);
22852285
if (!confirmed) return;

‎src/components/centre/StagingView.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ function visibleTreeRows(
166166
}
167167

168168
function shortHash(hash: string | null): string {
169-
return hash ? hash.slice(0, 8) : "-";
169+
return hash ? hash.slice(0, 7) : "-";
170170
}
171171

172172
function OperationInlineFeedback({

‎src/components/diff/DiffPanel.test.tsx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ describe("DiffPanel commit details", () => {
5959
mockGetCommitDetails.mockReset();
6060
});
6161

62+
it("shows seven-character commit hashes in the header", () => {
63+
renderCommitDetails(baseDetails);
64+
65+
expect(screen.getByText("Commit 0123456")).toBeInTheDocument();
66+
});
67+
6268
it("shows prose with preserved newlines separately from trailers", async () => {
6369
renderCommitDetails({
6470
...baseDetails,

‎src/components/diff/DiffPanel.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ type DiffPanelProps = {
190190
};
191191

192192
function compactHash(hash: string | null): string {
193-
return hash ? hash.slice(0, 12) : "None";
193+
return hash ? hash.slice(0, 7) : "None";
194194
}
195195

196196
export function DiffPanel({
@@ -333,7 +333,7 @@ export function DiffPanel({
333333
<FileIcon />
334334
<span className="diff-panel__filename">
335335
{mode === "log"
336-
? (selectedCommitHash ? t("header.commit", {hash: selectedCommitHash.slice(0, 8)}) : t("header.commitFiles"))
336+
? (selectedCommitHash ? t("header.commit", {hash: selectedCommitHash.slice(0, 7)}) : t("header.commitFiles"))
337337
: (selectedSubmodule ? t("header.submodule", {path: selectedSubmodule.path}) : (selectedFile ?? t("header.clickFile")))}
338338
</span>
339339
{mode === "changes" && hasSelectedFile && currentDiff && (

‎src/components/sidebar/CreateTagDialog.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export function CreateTagDialog({ existingTagNames, targetCommit, onConfirm, onC
5555
onConfirm(tagName.trim(), message.trim() || null);
5656
};
5757

58-
const targetLabel = targetCommit ? targetCommit.slice(0, 8) : "HEAD";
58+
const targetLabel = targetCommit ? targetCommit.slice(0, 7) : "HEAD";
5959

6060
return (
6161
<>

0 commit comments

Comments
 (0)