Fix setup_private_pods script for newly-cloned repos

- The Pods/ directory always exists even before submodules have been
  initialized; check for Pods/.git instead, which may be a file or
  a folder depending on how the submodule was set up.

- When cloning for the first time, make sure the remote is called
  'private' so that later updates will reference it correctly. Also
  run `git submodule absorbgitdirs` so that git stores the submodule
  state inside the top-level .git directory.

- For an existing directory, simplify the check for the presence of
  a proper 'private' remote.

- Check that we're running from the repository root so we don't get
  weird errors or do random clones.

- Make the script Shellcheck-clean.
This commit is contained in:
Jordan Rose
2022-01-26 17:19:17 -08:00
parent 8bdf9fbc44
commit 01fc3945ae

View File

@@ -1,11 +1,19 @@
#!/bin/bash
# shellcheck disable=SC2164 # pushd/popd failure
if [ ! -z ${USE_PRIVATE_PODS+x} ]; then
if [ ! -d Signal.xcodeproj ]; then
echo "error: Must be run from the repository root" >&2
exit 1
fi
if [ -n "${USE_PRIVATE_PODS+x}" ]; then
echo "Using private pods"
if [ -d "Pods" ]; then
if [ -e "Pods/.git" ]; then
pushd Pods
HAS_CONFIGURED_PRIVATE_REMOTE=`git remote -v | grep -ci 'signal-pods-private' || true`
if [ "$HAS_CONFIGURED_PRIVATE_REMOTE" = 0 ]; then
# FIXME: Possible failure modes here:
# - You have a Signal-Pods-Private remote not named 'private'.
# - You have a remote named 'private' that points somewhere else.
if ! git remote -v | grep -qi 'signal-pods-private'; then
echo "Adding private pods remote"
git remote add private git@github.com:signalapp/Signal-Pods-Private.git
fi
@@ -13,7 +21,13 @@ if [ ! -z ${USE_PRIVATE_PODS+x} ]; then
popd
else
echo "Cloning private pods repo"
git clone git@github.com:signalapp/Signal-Pods-Private.git Pods
git clone git@github.com:signalapp/Signal-Pods-Private.git -o private Pods
# Add the public repo as a remote explicitly.
# This is what would happen if you did `git submodule update --init` first,
# and it helps avoid confusing Jenkins for the nightly builder.
git -C Pods remote add origin git@github.com:signalapp/Signal-Pods.git
# Not strictly necessary, but consistent with doing `git submodule update --init` first.
git submodule absorbgitdirs Pods
fi
else
echo "Not using private pods. Define USE_PRIVATE_PODS in your environment to enable."