Merge pull request #1539 from suusuu0927/claude/detect-project-locale-fix-20260421

fix: make detect-project.sh locale-independent and handle Windows bac…
This commit is contained in:
Affaan Mustafa 2026-04-21 18:13:52 -04:00 committed by GitHub
commit 32e3a31c3e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -79,7 +79,11 @@ _clv2_detect_project() {
fi fi
# Derive project name from directory basename # Derive project name from directory basename
project_name=$(basename "$project_root") # Normalize Windows backslashes so basename works when CLAUDE_PROJECT_DIR
# is passed as e.g. C:\Users\...\project.
local _norm_root
_norm_root=$(printf '%s' "$project_root" | sed 's|\\|/|g')
project_name=$(basename "$_norm_root")
# Derive project ID: prefer git remote URL hash (portable across machines), # Derive project ID: prefer git remote URL hash (portable across machines),
# fall back to path hash (machine-specific but still useful) # fall back to path hash (machine-specific but still useful)
@ -100,8 +104,15 @@ _clv2_detect_project() {
local hash_input="${remote_url:-$project_root}" local hash_input="${remote_url:-$project_root}"
# Prefer Python for consistent SHA256 behavior across shells/platforms. # Prefer Python for consistent SHA256 behavior across shells/platforms.
# Pass the value via env var and encode as UTF-8 inside Python so the hash
# is locale-independent (shells vary between UTF-8 / CP932 / CP1252, which
# would otherwise produce different hashes for the same non-ASCII path).
if [ -n "$_CLV2_PYTHON_CMD" ]; then if [ -n "$_CLV2_PYTHON_CMD" ]; then
project_id=$(printf '%s' "$hash_input" | "$_CLV2_PYTHON_CMD" -c "import sys,hashlib; print(hashlib.sha256(sys.stdin.buffer.read()).hexdigest()[:12])" 2>/dev/null) project_id=$(_CLV2_HASH_INPUT="$hash_input" "$_CLV2_PYTHON_CMD" -c '
import os, hashlib
s = os.environ["_CLV2_HASH_INPUT"]
print(hashlib.sha256(s.encode("utf-8")).hexdigest()[:12])
' 2>/dev/null)
fi fi
# Fallback if Python is unavailable or hash generation failed. # Fallback if Python is unavailable or hash generation failed.
@ -115,7 +126,11 @@ _clv2_detect_project() {
# check if a project dir exists under the legacy hash and reuse it # check if a project dir exists under the legacy hash and reuse it
if [ "$legacy_hash_input" != "$hash_input" ] && [ -n "$_CLV2_PYTHON_CMD" ]; then if [ "$legacy_hash_input" != "$hash_input" ] && [ -n "$_CLV2_PYTHON_CMD" ]; then
local legacy_id="" local legacy_id=""
legacy_id=$(printf '%s' "$legacy_hash_input" | "$_CLV2_PYTHON_CMD" -c "import sys,hashlib; print(hashlib.sha256(sys.stdin.buffer.read()).hexdigest()[:12])" 2>/dev/null) legacy_id=$(_CLV2_HASH_INPUT="$legacy_hash_input" "$_CLV2_PYTHON_CMD" -c '
import os, hashlib
s = os.environ["_CLV2_HASH_INPUT"]
print(hashlib.sha256(s.encode("utf-8")).hexdigest()[:12])
' 2>/dev/null)
if [ -n "$legacy_id" ] && [ -d "${_CLV2_PROJECTS_DIR}/${legacy_id}" ] && [ ! -d "${_CLV2_PROJECTS_DIR}/${project_id}" ]; then if [ -n "$legacy_id" ] && [ -d "${_CLV2_PROJECTS_DIR}/${legacy_id}" ] && [ ! -d "${_CLV2_PROJECTS_DIR}/${project_id}" ]; then
# Migrate legacy directory to new hash # Migrate legacy directory to new hash
mv "${_CLV2_PROJECTS_DIR}/${legacy_id}" "${_CLV2_PROJECTS_DIR}/${project_id}" 2>/dev/null || project_id="$legacy_id" mv "${_CLV2_PROJECTS_DIR}/${legacy_id}" "${_CLV2_PROJECTS_DIR}/${project_id}" 2>/dev/null || project_id="$legacy_id"