Skip to content

fix(osx): use console owner instead of $USER in postinstall script#2279

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/create-answer-for-issue-1982
Draft

fix(osx): use console owner instead of $USER in postinstall script#2279
Copilot wants to merge 2 commits intomainfrom
copilot/create-answer-for-issue-1982

Conversation

Copy link

Copilot AI commented Mar 4, 2026

When Homebrew invokes the macOS .pkg installer, it explicitly clears USER, LOGNAME, and USERNAME from the environment. The postinstall script was using ${USER} to run git-credential-manager configure as the real user — but with USER unset, this ran as root, causing root to take ownership of ~/.gitconfig (or its symlink target). Subsequent installs then fail because the configure step can't write to the root-owned file.

Changes

  • src/osx/Installer.Mac/scripts/postinstall: Replace ${USER} with $(stat -f%Su /dev/console) to determine the logged-in console user. Unlike environment variables, /dev/console ownership reflects the active GUI session regardless of how the process environment was sanitized.
# Before
sudo -u ${USER} "$INSTALL_DESTINATION/git-credential-manager" configure

# After
REAL_USER=$(stat -f%Su /dev/console)
sudo -u "${REAL_USER}" "$INSTALL_DESTINATION/git-credential-manager" configure

This mirrors the existing pattern in uninstall.sh (which uses logname), but logname on macOS also reads from LOGNAME — also cleared by Homebrew — making stat /dev/console the more robust choice for the installer context.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…nstall script

Co-authored-by: marekzmyslowski <1062877+marekzmyslowski@users.noreply.github.com>
Copilot AI changed the title [WIP] Add response to user in issue 1982 fix(osx): use console owner instead of $USER in postinstall script Mar 4, 2026
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.

2 participants