-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-all.sh
executable file
·81 lines (68 loc) · 2.63 KB
/
update-all.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
cd "$(dirname "$0")"
nameRegex="/([^/ ]+)\.git$";
printf "Updating Masters...\n\n";
while read line; do
if ! [ -z "$line" ]; then
if [[ $line =~ $nameRegex ]]; then
name=${BASH_REMATCH[1]};
else
printf "error: Malformed repository descriptor: '$line'. Skipping...\n\n";
continue;
fi
if ! [ -d "Masters/$name" ]; then
printf "error: No repository found for '$name', skipping...\n\n";
continue;
fi
remoteRegex="/([^/ ]+)/$name";
if [[ $line =~ $remoteRegex ]]; then
remoteRepo=${BASH_REMATCH[1]};
else
printf "error: Malformed repository descriptor: '$line'. Skipping...\n\n";
continue;
fi
printf "Updating branches for '$name'...\n";
cwd=$(pwd);
cd "./Masters/$name";
git fetch "$remoteRepo"
currentBranch=$(git rev-parse --abbrev-ref HEAD);
for remoteBranch in `git branch -r | grep -v HEAD`; do
remoteBranch=$(echo "$remoteBranch" | tr -d '[:space:]');
branch="${remoteBranch#$remoteRepo/}";
if ! [[ $(git branch --list "$branch") ]]; then
printf "Checking out local copy of new remote branch '$branch'.\n";
git branch --track "$branch" "$remoteBranch";
fi
rrb="refs/remotes/$remoteRepo/$branch";
rlb="refs/heads/$branch";
behindCount=$(( $(git rev-list --count $rlb..$rrb 2>/dev/null) +0));
aheadCount=$(( $(git rev-list --count $rrb..$rlb 2>/dev/null) +0));
if [ "$behindCount" -gt 0 ]; then
if [ "$aheadCount" -gt 0 ]; then
echo "$branch is $behindCount commit(s) behind and $aheadCount commit(s) ahead of '$remoteBranch' and could not be fast-forwarded";
elif [ "$branch" == "$currentBranch" ]; then
git merge -q --ff-only $rrb;
else
git fetch "$remoteRepo" "$branch":"$branch";
fi
fi
done
cd "$cwd";
printf "done.\n\n";
fi
done < "./repo-list"
printf "Updating Builds...\n\n";
shopt -s nullglob
for build in ./Builds/*; do
cwd=$(pwd);
cd "$build";
currentBranch=$(git for-each-ref --format='%(upstream:short)' "$(git symbolic-ref -q HEAD)");
if [ -z "$currentBranch" ]; then
printf "Folder '$build' isn't linked to any build branch. Skipping...\n\n";
fi
printf "Updating '$currentBranch' in '$build'...\n";
git merge --ff-only "$currentBranch";
cd "$cwd";
printf "done.\n\n";
done
shopt -u nullglob