From a9aafc84b16e3def65e8f2761209db18e216da13 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 15 May 2026 04:08:56 +0100 Subject: [PATCH] fix: fetch git installer branch refs without tags --- scripts/install-cli.sh | 17 +++++++++-------- scripts/install.sh | 17 +++++++++-------- test/scripts/install-cli.test.ts | 11 ++++++++++- test/scripts/install-sh.test.ts | 11 ++++++++++- 4 files changed, 38 insertions(+), 18 deletions(-) diff --git a/scripts/install-cli.sh b/scripts/install-cli.sh index 13b188ce8714..1c5339f020d9 100755 --- a/scripts/install-cli.sh +++ b/scripts/install-cli.sh @@ -423,6 +423,15 @@ checkout_git_openclaw_ref() { return 0 fi + if git -C "$repo_dir" ls-remote --exit-code --heads origin "$ref" >/dev/null 2>&1; then + git -C "$repo_dir" fetch --no-tags origin "refs/heads/${ref}:refs/remotes/origin/${ref}" + git -C "$repo_dir" checkout -B "$ref" "origin/$ref" + if [[ "$GIT_UPDATE" == "1" ]]; then + git -C "$repo_dir" pull --rebase --no-tags || true + fi + return 0 + fi + git -C "$repo_dir" fetch --tags origin if git -C "$repo_dir" rev-parse --verify --quiet "refs/tags/${ref}^{commit}" >/dev/null; then @@ -430,14 +439,6 @@ checkout_git_openclaw_ref() { return 0 fi - if git -C "$repo_dir" ls-remote --exit-code --heads origin "$ref" >/dev/null 2>&1; then - git -C "$repo_dir" checkout -B "$ref" "origin/$ref" - if [[ "$GIT_UPDATE" == "1" ]]; then - git -C "$repo_dir" pull --rebase || true - fi - return 0 - fi - if git -C "$repo_dir" rev-parse --verify --quiet "${ref}^{commit}" >/dev/null; then git -C "$repo_dir" checkout --detach "$ref" return 0 diff --git a/scripts/install.sh b/scripts/install.sh index 8652cd008c54..945dded36206 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -1969,6 +1969,15 @@ checkout_git_openclaw_ref() { return 0 fi + if git -C "$repo_dir" ls-remote --exit-code --heads origin "$ref" >/dev/null 2>&1; then + run_quiet_step "Fetching requested version" git -C "$repo_dir" fetch --no-tags origin "refs/heads/${ref}:refs/remotes/origin/${ref}" + run_quiet_step "Checking out ${ref}" git -C "$repo_dir" checkout -B "$ref" "origin/$ref" + if [[ "$GIT_UPDATE" == "1" ]]; then + run_quiet_step "Updating repository" git -C "$repo_dir" pull --rebase --no-tags || true + fi + return 0 + fi + run_quiet_step "Fetching requested version" git -C "$repo_dir" fetch --tags origin if git -C "$repo_dir" rev-parse --verify --quiet "refs/tags/${ref}^{commit}" >/dev/null; then @@ -1976,14 +1985,6 @@ checkout_git_openclaw_ref() { return 0 fi - if git -C "$repo_dir" ls-remote --exit-code --heads origin "$ref" >/dev/null 2>&1; then - run_quiet_step "Checking out ${ref}" git -C "$repo_dir" checkout -B "$ref" "origin/$ref" - if [[ "$GIT_UPDATE" == "1" ]]; then - run_quiet_step "Updating repository" git -C "$repo_dir" pull --rebase || true - fi - return 0 - fi - if git -C "$repo_dir" rev-parse --verify --quiet "${ref}^{commit}" >/dev/null; then run_quiet_step "Checking out ${ref}" git -C "$repo_dir" checkout --detach "$ref" return 0 diff --git a/test/scripts/install-cli.test.ts b/test/scripts/install-cli.test.ts index 5d62045b293a..559c5f145d12 100644 --- a/test/scripts/install-cli.test.ts +++ b/test/scripts/install-cli.test.ts @@ -47,9 +47,18 @@ describe("install-cli.sh", () => { expect(result.stdout).toContain("main=main"); }); - it("fetches main without tags for git installs", () => { + it("fetches moving git refs without tags for git installs", () => { expect(script).toContain('git -C "$repo_dir" fetch --no-tags origin main'); + expect(script).toContain( + 'git -C "$repo_dir" fetch --no-tags origin "refs/heads/${ref}:refs/remotes/origin/${ref}"', + ); expect(script).toContain('git -C "$repo_dir" pull --rebase --no-tags || true'); + + const branchCheckIndex = script.indexOf('ls-remote --exit-code --heads origin "$ref"'); + const tagFetchIndex = script.indexOf("fetch --tags origin"); + expect(branchCheckIndex).toBeGreaterThan(-1); + expect(tagFetchIndex).toBeGreaterThan(-1); + expect(branchCheckIndex).toBeLessThan(tagFetchIndex); }); it("uses non-frozen lockfile installs only for moving git refs", () => { diff --git a/test/scripts/install-sh.test.ts b/test/scripts/install-sh.test.ts index eedabe1346df..c59b54450ad1 100644 --- a/test/scripts/install-sh.test.ts +++ b/test/scripts/install-sh.test.ts @@ -381,9 +381,18 @@ describe("install.sh", () => { expect(result.stdout).toContain("main=main"); }); - it("fetches main without tags for git installs", () => { + it("fetches moving git refs without tags for git installs", () => { expect(script).toContain('git -C "$repo_dir" fetch --no-tags origin main'); + expect(script).toContain( + 'git -C "$repo_dir" fetch --no-tags origin "refs/heads/${ref}:refs/remotes/origin/${ref}"', + ); expect(script).toContain('git -C "$repo_dir" pull --rebase --no-tags || true'); + + const branchCheckIndex = script.indexOf('ls-remote --exit-code --heads origin "$ref"'); + const tagFetchIndex = script.indexOf("fetch --tags origin"); + expect(branchCheckIndex).toBeGreaterThan(-1); + expect(tagFetchIndex).toBeGreaterThan(-1); + expect(branchCheckIndex).toBeLessThan(tagFetchIndex); }); it("uses non-frozen lockfile installs only for moving git refs", () => {