forked from chapter-three/next-drupal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync-repo.sh
executable file
·49 lines (36 loc) · 1.11 KB
/
sync-repo.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
# Script to sync packages to read-only git clones
#
# This handles file deletions, additions, and changes seamlessly
set -e # bail on errors
BRANCHES=$1
REPO=$2
GLOB=$3
# Allow BRANCHES to be a comma-seperated list.
BRANCH=$(echo $BRANCHES | cut -d "," -f 1)
TRACKING_BRANCH=$(echo $BRANCHES | cut -d "," -f 2)
BASE=$(pwd)
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
for folder in $GLOB; do
[ -d "$folder" ] || continue
cd $BASE
NAME=${folder##*/}
CLONE_DIR="__${NAME}__clone__"
# Note: redirect output to dev/null to avoid any possibility of leaking token
git clone --quiet --depth 1 --branch ${BRANCH} ${REPO}${NAME}.git $CLONE_DIR > /dev/null
cd $CLONE_DIR
# Delete all files (to handle deletions in monorepo)
find . | grep -v ".git" | grep -v "^\.*$" | xargs rm -rf
# Copy new files to the clone
cp -r $BASE/$folder/. .
if [ -n "$(git status --porcelain)" ]; then
git add .
git commit -m "$COMMIT_MESSAGE"
git push origin ${BRANCH}
fi
if [ "$TRACKING_BRANCH" != "$BRANCH" ]; then
git push origin ${BRANCH}:${TRACKING_BRANCH}
fi
cd $BASE
rm -rf $CLONE_DIR
done