Skip to content

Commit 3b2147f

Browse files
committed
fix(install): require checkout HEAD commit object
1 parent 1bc1c23 commit 3b2147f

6 files changed

Lines changed: 14 additions & 6 deletions

File tree

‎scripts/install-cli.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ install_openclaw_from_git() {
11871187
ensure_pnpm_binary_for_scripts
11881188

11891189
if [[ -d "$repo_dir/.git" ]] &&
1190-
! git --git-dir="$repo_dir/.git" --work-tree="$repo_dir" rev-parse --verify --quiet HEAD >/dev/null 2>&1; then
1190+
! git --git-dir="$repo_dir/.git" --work-tree="$repo_dir" rev-parse --verify --quiet 'HEAD^{commit}' >/dev/null 2>&1; then
11911191
fail "Git checkout has no commit: ${repo_dir}. Move or remove this incomplete checkout, then retry."
11921192
fi
11931193

‎scripts/install.ps1‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1469,7 +1469,7 @@ function Assert-GitCheckoutHasCommit {
14691469

14701470
$hasHead = $false
14711471
try {
1472-
git "--git-dir=$gitDir" "--work-tree=$RepoDir" rev-parse --verify --quiet HEAD 2>$null | Out-Null
1472+
git "--git-dir=$gitDir" "--work-tree=$RepoDir" rev-parse --verify --quiet "HEAD^{commit}" 2>$null | Out-Null
14731473
$hasHead = ($LASTEXITCODE -eq 0)
14741474
} catch {}
14751475
if (-not $hasHead) {

‎scripts/install.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2424,7 +2424,7 @@ validate_git_checkout_head() {
24242424
if [[ ! -d "$repo_dir/.git" ]]; then
24252425
return 0
24262426
fi
2427-
if git --git-dir="$repo_dir/.git" --work-tree="$repo_dir" rev-parse --verify --quiet HEAD >/dev/null 2>&1; then
2427+
if git --git-dir="$repo_dir/.git" --work-tree="$repo_dir" rev-parse --verify --quiet 'HEAD^{commit}' >/dev/null 2>&1; then
24282428
return 0
24292429
fi
24302430

‎test/scripts/install-cli.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ describe("install-cli.sh", () => {
5454
git() {
5555
[[ "$1" == "--git-dir=$repo/.git" ]] &&
5656
[[ "$2" == "--work-tree=$repo" ]] &&
57+
[[ "$3" == "rev-parse" ]] &&
58+
[[ "$4" == "--verify" ]] &&
59+
[[ "$5" == "--quiet" ]] &&
60+
[[ "$6" == "HEAD^{commit}" ]] &&
5761
return 1
5862
return 99
5963
}

‎test/scripts/install-ps1.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ describe("install.ps1 failure handling", () => {
663663

664664
expect(guardBody).toContain('"--git-dir=$gitDir"');
665665
expect(guardBody).toContain('"--work-tree=$RepoDir"');
666-
expect(guardBody).toContain("rev-parse --verify --quiet HEAD");
666+
expect(guardBody).toContain('rev-parse --verify --quiet "HEAD^{commit}"');
667667
expect(guardBody).toContain("Git checkout has no commit");
668668
expect(guardBody).not.toContain("Remove-Item");
669669
expect(guardBody).not.toContain("Move-Item");

‎test/scripts/install-sh.test.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ NODE
323323
ui_success() { :; }
324324
ui_error() { printf 'error:%s\\n' "$*"; }
325325
git() {
326-
if [[ "$1" == "--git-dir=$repo/.git" && "$2" == "--work-tree=$repo" && "$3" == "rev-parse" ]]; then
326+
if [[ "$1" == "--git-dir=$repo/.git" && "$2" == "--work-tree=$repo" && "$3" == "rev-parse" && "$6" == "HEAD^{commit}" ]]; then
327327
return 0
328328
fi
329329
if [[ "$1" == "-C" && "$3" == "status" ]]; then
@@ -360,7 +360,11 @@ NODE
360360
touch "$parent/seed"
361361
git -C "$parent" add seed
362362
git -C "$parent" commit -qm seed
363-
mkdir -p "$repo/.git"
363+
mkdir -p "$repo"
364+
git -C "$repo" init -q
365+
printf 'ref: refs/heads/main\\n' > "$repo/.git/HEAD"
366+
mkdir -p "$repo/.git/refs/heads"
367+
printf '1111111111111111111111111111111111111111\\n' > "$repo/.git/refs/heads/main"
364368
printf 'keep\\n' > "$repo/local.txt"
365369
ui_info() { :; }
366370
ui_error() { :; }

0 commit comments

Comments
 (0)