mirror of
https://github.com/ultraworkers/claw-code.git
synced 2026-04-24 13:08:11 +08:00
merge: fix/jobdori-161-worktree-git-sha — diagnostic-strictness family
Fix: resolve actual HEAD path in git worktrees for correct Git SHA in build metadata. In worktrees, .git is a pointer file not a directory, so cargo's rerun-if-changed=.git/HEAD never triggers. Per MERGE_CHECKLIST.md Cluster 2 (P1 Diagnostic-strictness, isolated): - 25 lines in build.rs only (no crate-level conflicts) - Verified: build → commit → rebuild → SHA updates correctly Diagnostic-strictness family member (joins #122/#122b). Applied: execution artifact runbook. Cycle #72 integration.
This commit is contained in:
commit
d5373ac5d6
@ -1,6 +1,24 @@
|
|||||||
use std::env;
|
use std::env;
|
||||||
|
use std::path::Path;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
|
fn resolve_git_head_path() -> Option<String> {
|
||||||
|
let git_path = Path::new(".git");
|
||||||
|
if git_path.is_file() {
|
||||||
|
// Worktree: .git is a pointer file containing "gitdir: /path/to/real/.git/worktrees/<name>"
|
||||||
|
if let Ok(content) = std::fs::read_to_string(git_path) {
|
||||||
|
if let Some(gitdir) = content.strip_prefix("gitdir:") {
|
||||||
|
let gitdir = gitdir.trim();
|
||||||
|
return Some(format!("{}/HEAD", gitdir));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if git_path.is_dir() {
|
||||||
|
// Regular repo: .git is a directory
|
||||||
|
return Some(".git/HEAD".to_string());
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Get git SHA (short hash)
|
// Get git SHA (short hash)
|
||||||
let git_sha = Command::new("git")
|
let git_sha = Command::new("git")
|
||||||
@ -52,6 +70,12 @@ fn main() {
|
|||||||
println!("cargo:rustc-env=BUILD_DATE={build_date}");
|
println!("cargo:rustc-env=BUILD_DATE={build_date}");
|
||||||
|
|
||||||
// Rerun if git state changes
|
// Rerun if git state changes
|
||||||
println!("cargo:rerun-if-changed=.git/HEAD");
|
// In worktrees, .git is a pointer file, so watch the actual HEAD location
|
||||||
|
if let Some(head_path) = resolve_git_head_path() {
|
||||||
|
println!("cargo:rerun-if-changed={}", head_path);
|
||||||
|
} else {
|
||||||
|
// Fallback to .git/HEAD for regular repos (won't trigger in worktrees, but prevents silent failure)
|
||||||
|
println!("cargo:rerun-if-changed=.git/HEAD");
|
||||||
|
}
|
||||||
println!("cargo:rerun-if-changed=.git/refs");
|
println!("cargo:rerun-if-changed=.git/refs");
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user