-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
package/scripts/postinstall: avoid writing to ~/.gitconfig
#17068
Conversation
We can eliminate permission issues by not touching `~/.gitconfig` at all. Fixes #17067.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good assuming https://github.com/Homebrew/brew/actions/runs/8635175757/job/23672332197?pr=17068 is!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It fails with fatal: detected dubious ownership in repository at '/usr/local/Homebrew'
if I don't remove my existing installation, unfortunately. This is probably the original reason why set_git_safe_directory
was introduced:
2024-04-11 01:37:54+08 Ruoyus-Mac package_script_service[2641]: ./postinstall: fatal: detected dubious ownership in repository at '/usr/local/Homebrew'
2024-04-11 01:37:54+08 Ruoyus-Mac package_script_service[2641]: ./postinstall: To add an exception for this directory, call:
2024-04-11 01:37:54+08 Ruoyus-Mac package_script_service[2641]: ./postinstall: git config --global --add safe.directory /usr/local/Homebrew
ls -al /usr/local/Homebrew
$ ls -al /usr/local/Homebrew
total 104
drwxr-xr-x 24 ruoyu admin 768 Apr 11 01:48 .
drwxr-xr-x 14 root wheel 448 Apr 11 01:47 ..
drwxr-xr-x 5 ruoyu admin 160 Apr 11 01:47 .devcontainer
-rw-r--r-- 1 ruoyu admin 51 Apr 11 01:47 .dockerignore
-rw-r--r-- 1 ruoyu admin 380 Apr 11 01:47 .editorconfig
drwxr-xr-x 14 root wheel 448 Apr 11 01:48 .git
drwxr-xr-x 12 ruoyu admin 384 Apr 11 01:47 .github
-rw-r--r-- 1 ruoyu admin 5867 Apr 11 01:47 .gitignore
-rw-r--r-- 1 ruoyu admin 1342 Apr 11 01:47 .shellcheckrc
drwxr-xr-x 3 ruoyu admin 96 Apr 11 01:47 .sublime
-rw-r--r-- 1 ruoyu admin 65 Apr 11 01:47 .vale.ini
drwxr-xr-x 4 ruoyu admin 128 Apr 11 01:47 .vscode
-rw-r--r-- 1 ruoyu admin 207 Apr 11 01:47 CHANGELOG.md
-rw-r--r-- 1 ruoyu admin 829 Apr 11 01:47 CONTRIBUTING.md
-rw-r--r-- 1 ruoyu admin 2984 Apr 11 01:47 Dockerfile
-rw-r--r-- 1 ruoyu admin 1334 Apr 11 01:47 LICENSE.txt
drwxr-xr-x 5 ruoyu admin 160 Apr 11 01:47 Library
-rw-r--r-- 1 ruoyu admin 8882 Apr 11 01:47 README.md
drwxr-xr-x 3 ruoyu admin 96 Apr 11 01:47 bin
drwxr-xr-x 11 root wheel 352 Apr 11 01:12 cache_api
drwxr-xr-x 7 ruoyu admin 224 Apr 11 01:47 completions
drwxr-xr-x 75 ruoyu admin 2400 Apr 11 01:47 docs
drwxr-xr-x 4 ruoyu admin 128 Apr 11 01:47 manpages
drwxr-xr-x 5 ruoyu admin 160 Apr 11 01:47 package
While the fix is easy, I think there's some value in making sure CI fails in this case.
Ah, no wonder why CI didn't fail. The macOS runner image has the following in [safe]
directory = * |
Good news: CI is now able to catch a Bad news: as CI suggests, this unfortunately does not work on macOS 12, whose CLT provide Git 2.37.1. Git only started to respect Will have to think of another way to handle this. |
In this attempt we pretend that the "global" configs are in the repository itself. $ XDG_CONFIG_HOME= HOME=$PWD git config --global section.key value $ XDG_CONFIG_HOME= HOME=$PWD git config --global section.key value $ git config --global section.key $ cat $PWD/.gitconfig [section] key = value
Confirmed locally that this is working as expected and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work on the approach here @ZhongRuoyu!
Perhaps an easier option would be overriding HOME
for the entire script; it's all run as root
anyway so the HOME
pointing to the running user is erroneous and unneeded.
It is safe to override `HOME` for the entire script as only Git uses it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, thanks again @ZhongRuoyu!
brew style
with your changes locally?brew typecheck
with your changes locally?brew tests
with your changes locally?We can eliminate permission issues by not touching
~/.gitconfig
at all.We pretend that the "global" configs are in the repository itself by overriding
XDG_CONFIG_HOME
andHOME
. For example:Fixes #17067.
Needs testing as I haven't tried to build a.pkg
locally.