From 618e259b0bc1c4c1427f6ef7b4f37a36b34b57aa Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Mar 2026 14:25:01 +0000 Subject: [PATCH 1/3] Initial plan From 1832f5817e39bf4cadc8baa0b4672e5e9a038f68 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Mar 2026 14:29:16 +0000 Subject: [PATCH 2/3] fix(osx): use stat -f%Su /dev/console to determine real user in postinstall script Co-authored-by: marekzmyslowski <1062877+marekzmyslowski@users.noreply.github.com> --- src/osx/Installer.Mac/scripts/postinstall | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/osx/Installer.Mac/scripts/postinstall b/src/osx/Installer.Mac/scripts/postinstall index 9eed9aa7a..403ced46f 100755 --- a/src/osx/Installer.Mac/scripts/postinstall +++ b/src/osx/Installer.Mac/scripts/postinstall @@ -31,7 +31,10 @@ mkdir -p /usr/local/bin /bin/ln -Fs "$INSTALL_DESTINATION/git-credential-manager" /usr/local/bin/git-credential-manager # Configure GCM for the current user (running as the current user to avoid root -# from taking ownership of ~/.gitconfig) -sudo -u ${USER} "$INSTALL_DESTINATION/git-credential-manager" configure +# from taking ownership of ~/.gitconfig). +# Use stat to determine the console user since the installer may be invoked with +# USER unset (e.g. when run via Homebrew which explicitly clears USER). +REAL_USER=$(stat -f%Su /dev/console) +sudo -u "${REAL_USER}" "$INSTALL_DESTINATION/git-credential-manager" configure exit 0 From 66ac576b331522bdf58c1a9ca379309dd1fe0066 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 12 Mar 2026 09:42:16 +0000 Subject: [PATCH 3/3] fix(osx): handle headless/SSH installs in postinstall with SUDO_USER fallback Co-authored-by: marekzmyslowski <1062877+marekzmyslowski@users.noreply.github.com> --- src/osx/Installer.Mac/scripts/postinstall | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/osx/Installer.Mac/scripts/postinstall b/src/osx/Installer.Mac/scripts/postinstall index 403ced46f..4d64599b6 100755 --- a/src/osx/Installer.Mac/scripts/postinstall +++ b/src/osx/Installer.Mac/scripts/postinstall @@ -32,9 +32,21 @@ mkdir -p /usr/local/bin # Configure GCM for the current user (running as the current user to avoid root # from taking ownership of ~/.gitconfig). -# Use stat to determine the console user since the installer may be invoked with -# USER unset (e.g. when run via Homebrew which explicitly clears USER). -REAL_USER=$(stat -f%Su /dev/console) -sudo -u "${REAL_USER}" "$INSTALL_DESTINATION/git-credential-manager" configure +# Determine the real (non-root) user via multiple methods since the installer +# may be invoked with USER/LOGNAME unset (e.g. when run via Homebrew which +# explicitly clears those environment variables). +# 1. SUDO_USER - set by sudo, works for both GUI (Homebrew) and SSH scenarios. +# 2. stat /dev/console - works for GUI sessions when not running under sudo. +REAL_USER="${SUDO_USER}" +if [ -z "${REAL_USER}" ] || [ "${REAL_USER}" = "root" ]; then + REAL_USER=$(stat -f%Su /dev/console 2>/dev/null) +fi + +if [ -n "${REAL_USER}" ] && [ "${REAL_USER}" != "root" ]; then + sudo -u "${REAL_USER}" "$INSTALL_DESTINATION/git-credential-manager" configure +else + echo "warning: unable to determine the installing user; GCM has not been configured automatically." >&2 + echo "warning: run 'git-credential-manager configure' to configure GCM for your user." >&2 +fi exit 0