-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.sh
47 lines (42 loc) · 1.17 KB
/
update.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
#!/bin/bash
git config user.name $USERNAME
git config user.email $EMAIL
git config checkout.defaultRemote origin
git fetch origin
git checkout master
git remote add upstream https://github.com/QuinnWuest/KtaneSmallfont
git fetch upstream
if [ $? -ne 0 ]; then
echo "Failed to fetch the original repo, exiting..."
exit 128
fi
containsElement () {
local e match="$1"
shift
for e; do [[ "$e" == "$match" ]] && return 1; done
return 0
}
ORIGIN=()
UPSTREAM=()
for branch in $(git branch -r | tr "\n" "\n"); do
if [[ "$branch" != "->" && "$branch" != "origin/HEAD" && "$branch" != "upstream/updater_workflow" ]]; then
ARR=($( cut -d '/' -f 1 <<< "$branch" ) $( cut -d '/' -f 2- <<< "$branch" ))
if [[ "${ARR[0]}" == "origin" ]]; then
ORIGIN+=("${ARR[1]}")
else
UPSTREAM+=("${ARR[1]}")
fi
fi
done
for branch in "${UPSTREAM[@]}"; do
echo "Preparing $branch"
containsElement "$branch" "${ORIGIN[@]}"
if [ $? -eq 0 ]; then
git switch --orphan $branch
else
git checkout $branch
fi
echo "Pushing $branch"
git reset --hard upstream/$branch
git push -f https://$USERNAME:[email protected]/$REPOSITORY.git $branch
done