Last active
April 19, 2016 17:36
-
-
Save 6/2f06824c78ae82e6a588b723d2d4e967 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Converts string such as "git version 2.6.4 (Apple Git-63)" into "264" | |
function numeric_git_version { | |
git --version | sed 's/git version //g' | sed 's/ (Apple Git-[0-9]*)//g' | sed 's/\.//g' | |
} | |
function fix_git { | |
echo "Ensuring that /usr/local is writable for homebrew. Please enter your password:" | |
sudo chown -R $(whoami):admin /usr/local | |
echo "Updating homebrew..." | |
brew update | |
if [[ -z "$(brew list -1 | grep '^git$')" ]]; then | |
echo "Installing newest git using homebrew..." | |
brew install git | |
else | |
echo "Upgrading to newest git using homebrew..." | |
brew upgrade git | |
fi | |
echo "Symlinking homebrew git to Xcode git..." | |
sudo mv /Applications/Xcode.app/Contents/Developer/usr/bin/{git,oldgit} | |
sudo ln -s /usr/local/bin/git /Applications/Xcode.app/Contents/Developer/usr/bin/git | |
echo "Done! Please open a new terminal tab/window to have changes take effect." | |
} | |
if [[ "$(numeric_git_version)" -le 273 ]]; then | |
echo "WARNING: You are using a vulnerable version of git." | |
echo "Attempting to fix automatically..." | |
fix_git | |
else | |
echo "You are using a safe version of git. Good job!" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment