Skip to content

Commit

Permalink
package/scripts/postinstall: simplify
Browse files Browse the repository at this point in the history
It is safe to override `HOME` for the entire script as only Git uses it.
  • Loading branch information
ZhongRuoyu committed Apr 11, 2024
1 parent f764428 commit 8a0b4ed
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions package/scripts/postinstall
Expand Up @@ -21,16 +21,17 @@ fi
# add Git to path
export PATH="/Library/Developer/CommandLineTools/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:${PATH}"

# avoid writing to user's global config file by overriding HOME
# https://git-scm.com/docs/git-config#SCOPES
unset XDG_CONFIG_HOME
export HOME="${homebrew_directory}"

# reset Git repository
cd "${homebrew_directory}"
# avoid writing user's global config file by making
# "${homebrew_directory}/.gitconfig" the "global" config
# https://git-scm.com/docs/git-config#SCOPES
git=(env XDG_CONFIG_HOME="" HOME="${homebrew_directory}" git)
"${git[@]}" config --global --add safe.directory "${homebrew_directory}"
"${git[@]}" reset --hard
"${git[@]}" checkout --force master
"${git[@]}" branch | grep -v '\*' | xargs -n 1 "${git[@]}" branch --delete --force || true
git config --global --add safe.directory "${homebrew_directory}"
git reset --hard
git checkout --force master
git branch | grep -v '\*' | xargs -n 1 git branch --delete --force || true
rm "${homebrew_directory}/.gitconfig"

# move to /usr/local if on x86_64
Expand All @@ -41,10 +42,10 @@ then
cp -pRL "${homebrew_directory}/.git" "/usr/local/Homebrew/"
mv "${homebrew_directory}/cache_api" "/usr/local/Homebrew/"

git=(env XDG_CONFIG_HOME="" HOME="/usr/local/Homebrew" git)
"${git[@]}" config --global --add safe.directory /usr/local/Homebrew
"${git[@]}" -C /usr/local/Homebrew reset --hard
"${git[@]}" -C /usr/local/Homebrew checkout --force master
export HOME="/usr/local/Homebrew"
git config --global --add safe.directory /usr/local/Homebrew
git -C /usr/local/Homebrew reset --hard
git -C /usr/local/Homebrew checkout --force master
rm /usr/local/Homebrew/.gitconfig
else
mkdir -vp /usr/local/bin
Expand Down

0 comments on commit 8a0b4ed

Please sign in to comment.