forked from scratchfoundation/scratch-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-batch-push.sh
More file actions
53 lines (43 loc) · 1.51 KB
/
git-batch-push.sh
File metadata and controls
53 lines (43 loc) · 1.51 KB
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
50
51
52
53
#!/bin/bash
DEST_BRANCHES="
develop,250 \
scratch-android,250 \
scratch-desktop,250 \
main,250 \
gh-pages,1 \
"
BUILD_OUT="./monorepo.out"
# set organization to where you have forked the repository
GITHUB_ORG=""
BASE_REPO="scratch-editor"
# https://gist.github.com/spenserhale/19a2abd03c0558449202a1d7bcc64ed7
batch_push_branch () {
REMOTE=origin
BRANCH="$1"
BATCH_SIZE=$2
git -C "$BUILD_OUT" checkout "$BRANCH"
# check if the branch exists on the remote
if git -C "$BUILD_OUT" show-ref --quiet --verify refs/remotes/$REMOTE/$BRANCH; then
# if so, only push the commits that are not on the remote already
range=$REMOTE/$BRANCH..HEAD
else
# else push all the commits
range=HEAD
fi
# count the number of commits to push
n=$(git -C "$BUILD_OUT" log --first-parent --format=format:x $range | wc -l)
# push each batch
for i in $(seq $n -$BATCH_SIZE 1); do
# get the hash of the commit to push
h=$(git -C "$BUILD_OUT" log --first-parent --reverse --format=format:%H --skip $i -n1)
echo "Pushing $h..."
git -C "$BUILD_OUT" push $REMOTE ${h}:refs/heads/$BRANCH
done
# push the final partial batch
git -C "$BUILD_OUT" push $REMOTE HEAD:refs/heads/$BRANCH
}
git -C "$BUILD_OUT" remote set-url origin "[email protected]:${GITHUB_ORG}/${BASE_REPO}.git"
for BRANCH_DATA in $DEST_BRANCHES; do
IFS=, read -r BRANCH_NAME BATCH_SIZE <<< "$BRANCH_DATA"
batch_push_branch "$BRANCH_NAME" $BATCH_SIZE
done