Skip to content

fix: use authenticated Homebrew tap checkout - #17

Merged
robjtede merged 1 commit into
mainfrom
fix/homebrew-app-token-http-auth
Aug 10, 2026
Merged

fix: use authenticated Homebrew tap checkout#17
robjtede merged 1 commit into
mainfrom
fix/homebrew-app-token-http-auth

Conversation

@robjtede

@robjtede robjtede commented Aug 9, 2026

Copy link
Copy Markdown
Member

The Homebrew updater now requires a caller-provided tap checkout and uses ordinary Git commands inside it. Authentication is owned by the workflow that prepared the checkout, which lets consumers pass a scoped GitHub App token through actions/checkout instead of duplicating its credential handling.

--tap-directory is now a documented option and can still be supplied through X52_HOMEBREW_TAP_DIRECTORY. The updater fails early when no checkout is provided. The fixture verifies plain Git fetch and push commands and covers the missing-checkout error.

Validation: just check.

Summary by CodeRabbit

  • Improvements
    • Homebrew tap updates now use the Git credentials already configured in the existing checkout.
    • Tap updates require an existing checkout specified through the command-line option or environment setting.
    • Added clearer help text explaining how to provide the tap checkout.
    • Added validation and an actionable error when no tap checkout is configured.

@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The Homebrew updater now requires an existing tap checkout from --tap-directory or X52_HOMEBREW_TAP_DIRECTORY. It uses direct Git commands and no longer configures Git credentials or clones a temporary checkout.

Changes

Homebrew tap update

Layer / File(s) Summary
Require existing tap checkout and use direct Git
release-tools/update-homebrew-tap.py
The updater documents and validates the tap directory. It performs branch lookup, fetch, and push with direct Git commands.
Validate tap directory and credential behavior
release-tools/test.bash
Tests expect a normal tap push, reject gh auth setup-git, remove credential-helper checks, and verify the missing tap-directory error.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant update_homebrew_tap.py
  participant ExistingTapCheckout
  participant Git
  update_homebrew_tap.py->>ExistingTapCheckout: Select --tap-directory or X52_HOMEBREW_TAP_DIRECTORY
  update_homebrew_tap.py->>Git: Look up branch and fetch
  update_homebrew_tap.py->>Git: Push with --set-upstream
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: using an authenticated Homebrew tap checkout.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/homebrew-app-token-http-auth

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@robjtede
robjtede force-pushed the fix/homebrew-app-token-http-auth branch from bc6eb5a to e459e92 Compare August 10, 2026 02:10
@robjtede robjtede changed the title fix: use App token for Homebrew Git requests fix: use authenticated Homebrew tap checkout Aug 10, 2026
@robjtede
robjtede marked this pull request as ready for review August 10, 2026 02:13

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@release-tools/update-homebrew-tap.py`:
- Around line 288-290: Update the existing-branch fetch logic in
release-tools/update-homebrew-tap.py lines 288-290 to explicitly create or
update the origin/<branch> remote-tracking ref before the later git switch
--track operation, rather than relying on FETCH_HEAD. Apply the same
remote-tracking-ref fix in release-tools/test.bash lines 292-296; both sites
must ensure origin/<branch> is available after fetching.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b59a6140-00f6-420e-be3f-a413d2c5ef2f

📥 Commits

Reviewing files that changed from the base of the PR and between ab12f8a and e459e92.

📒 Files selected for processing (2)
  • release-tools/test.bash
  • release-tools/update-homebrew-tap.py

Comment on lines +288 to +290
if run(git, "-C", str(tap_directory), "ls-remote", "--exit-code", "--heads", "origin", branch, check=False).returncode == 0:
log(f"Reusing tap branch {branch}")
run_authenticated_git(git, gh, "-C", str(tap_directory), "fetch", "origin", branch)
run(git, "-C", str(tap_directory), "fetch", "origin", branch)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

root="$(mktemp -d)"
trap 'rm -rf "$root"' EXIT

git init --bare "$root/origin.git"
git init -b main "$root/source"
git -C "$root/source" config user.name test
git -C "$root/source" config user.email test@example.invalid
git -C "$root/source" commit --allow-empty -m initial
git -C "$root/source" branch release/test
git -C "$root/source" remote add origin "$root/origin.git"
git -C "$root/source" push origin main release/test

git clone --single-branch --branch main "$root/origin.git" "$root/checkout"
git -C "$root/checkout" fetch origin release/test

if git -C "$root/checkout" show-ref --verify --quiet refs/remotes/origin/release/test; then
  echo "Unexpected remote-tracking ref" >&2
  exit 1
fi

if git -C "$root/checkout" switch --track origin/release/test; then
  echo "Expected switch to fail without origin/release/test" >&2
  exit 1
fi

Repository: x52dev/nix

Length of output: 1187


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the relevant code and fake Git command behavior enough to determine
# whether `git fetch origin <branch>` currently creates `refs/remotes/origin/<branch>`.
printf '--- release-tools/update-homebrew-tap.py relevant lines ---\n'
sed -n '250,315p' release-tools/update-homebrew-tap.py

printf '\n--- release-tools/test.bash relevant lines ---\n'
sed -n '260,310p' release-tools/test.bash

printf '\n--- fake-git command wrapper (if any) ---\n'
rg -n "real_git|git|update-homebrew-tap|switch --track|fetch origin|refs/remotes/origin" release-tools -S

printf '\n--- git version ---\n'
git --version

Repository: x52dev/nix

Length of output: 239


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- release-tools/update-homebrew-tap.py relevant lines ---'
sed -n '250,315p' release-tools/update-homebrew-tap.py

printf '%s\n' ''
printf '%s\n' '--- release-tools/test.bash relevant lines ---'
sed -n '260,310p' release-tools/test.bash

printf '%s\n' ''
printf '%s\n' '--- relevant searches ---'
rg -n "real_git|git|update-homebrew-tap|switch --track|fetch origin|refs/remotes/origin|ls-remote|push" release-tools -S || true

printf '%s\n' ''
printf '%s\n' '--- git version ---'
git --version

Repository: x52dev/nix

Length of output: 16187


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- release-tools/test.bash fake git wrapper ---'
sed -n '140,185p' release-tools/test.bash

printf '%s\n' ''
printf '%s\n' '--- behavioral probe for git fetch explicit source-only refspec ---'
root="$(mktemp -d)"
trap 'rm -rf "$root"' EXIT

git init --bare "$root/origin.git"
git init -b main "$root/source"
git -C "$root/source" config user.name test
git -C "$root/source" config user.email test@example.invalid
git -C "$root/source" commit --allow-empty -m initial
git -C "$root/source" branch release/test
git -C "$root/source" remote add origin "$root/origin.git"
git -C "$root/source" push origin main release/test

git clone --single-branch --branch main "$root/origin.git" "$root/checkout"
git -C "$root/checkout" fetch origin release/test

printf '%s\n' 'remote-tracking ref exists:'
git -C "$root/checkout" show-ref --verify --quiet refs/remotes/origin/release/test && printf 'yes\n' || printf 'no\n'

printf '%s\n' 'FETCH_HEAD:'
git -C "$root/checkout" show-ref --verify --quiet FETCH_HEAD && printf 'yes\n' || printf 'no\n'

set +e
git -C "$root/checkout" switch --track origin/release/test
rc=$?
printf '%s\n' "switch --track origin/release/test exit code: $rc"
set -e

Repository: x52dev/nix

Length of output: 2810


Create the remote-tracking ref before tracking it.

git fetch origin <branch> stores the result in FETCH_HEAD when no remote tracking refspec exists, so git switch --track origin/<branch> fails with invalid reference: origin/<branch>.

Proposed fix
-            run(git, "-C", str(tap_directory), "fetch", "origin", branch)
+            run(
+                git,
+                "-C",
+                str(tap_directory),
+                "fetch",
+                "origin",
+                f"refs/heads/{branch}:refs/remotes/origin/{branch}",
+            )
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if run(git, "-C", str(tap_directory), "ls-remote", "--exit-code", "--heads", "origin", branch, check=False).returncode == 0:
log(f"Reusing tap branch {branch}")
run_authenticated_git(git, gh, "-C", str(tap_directory), "fetch", "origin", branch)
run(git, "-C", str(tap_directory), "fetch", "origin", branch)
if run(git, "-C", str(tap_directory), "ls-remote", "--exit-code", "--heads", "origin", branch, check=False).returncode == 0:
log(f"Reusing tap branch {branch}")
run(
git,
"-C",
str(tap_directory),
"fetch",
"origin",
f"refs/heads/{branch}:refs/remotes/origin/{branch}",
)
📍 Affects 2 files
  • release-tools/update-homebrew-tap.py#L288-L290 (this comment)
  • release-tools/test.bash#L292-L296
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@release-tools/update-homebrew-tap.py` around lines 288 - 290, Update the
existing-branch fetch logic in release-tools/update-homebrew-tap.py lines
288-290 to explicitly create or update the origin/<branch> remote-tracking ref
before the later git switch --track operation, rather than relying on
FETCH_HEAD. Apply the same remote-tracking-ref fix in release-tools/test.bash
lines 292-296; both sites must ensure origin/<branch> is available after
fetching.

@robjtede
robjtede merged commit 4253f74 into main Aug 10, 2026
3 checks passed
@robjtede
robjtede deleted the fix/homebrew-app-token-http-auth branch August 10, 2026 02:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant