Skip to content

Instantly share code, notes, and snippets.

@danielcarr
Forked from kreeger/pod-install-post-checkout
Last active September 16, 2022 12:38
Show Gist options
  • Save danielcarr/337b5cf0ddb6c1931c5a to your computer and use it in GitHub Desktop.
Save danielcarr/337b5cf0ddb6c1931c5a to your computer and use it in GitHub Desktop.
A post-checkout hook for running pod install if necessary checking out a branch

pod-update-post-checkout

Keep your installed pods up-to-date between branch checkouts! This is a git post-checkout hook for running a pod install if necessary when a pulling changes or changing branches in your local git repository.

Install with

curl https://gist.githubusercontent.com/danielcarr/337b5cf0ddb6c1931c5a/raw > .git/hooks/post-checkout
chmod +x .git/hooks/post-checkout
#!/usr/bin/env sh
from_branch=$1
checked_out_branch=$2
check_out_type=$3 # changing branches = 1; checking out a file = 0
# If checking out a fresh clone
if test $from_branch = 0000000000000000000000000000000000000000 ; then
from_branch=`git hash-object -t tree /dev/null` # a hash representing an empty tree/repo
fi
# If Podfile exists and `pod install` does something
if test -f Podfile && command -v pod >/dev/null &&
# And the Podfile.lock has changed
! git diff $from_branch $checked_out_branch --quiet -- Podfile.lock
then
unset -v GIT_DIR # In case git thinks it's somewhere else
pod install
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment