-
Notifications
You must be signed in to change notification settings - Fork 2
/
bubble-up-changes.sh
executable file
·74 lines (64 loc) · 2.08 KB
/
bubble-up-changes.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
#!/usr/bin/env bash
# Like this script?
# Generate boilerplate for similar ones at https://bashplate.wolfgang-werner.net.
set -o errexit # exit on error
set -o nounset # don't allow unset variables
# set -o xtrace # enable for debugging
usage() {
printf "Bubble up changes through multiple branches according to the sequence in .lesson-branch-sequence and optionally push them.\n"
printf "Usage: $(basename "$0") "
printf -- "[-h] "
printf -- "[-v] "
printf -- "[-p] "
printf "\n"
printf " -%s\t%s - %s%s\n" "h" "help" "Show this help message." ""
printf " -%s\t%s - %s%s\n" "v" "version" "Show version information." ""
printf " -%s\t%s - %s%s\n" "p" "push" "Push all updated branches - know what you're doing" ""
}
version() {
printf "0.0.1\n"
}
# default values
opt_help="false"
opt_version="false"
opt_push="false"
# declared functions
# option parsing
OPTSPEC=:hvp
while getopts $OPTSPEC option; do
case "$option" in
h ) opt_help="true"; usage; exit 0 ;;
v ) opt_version="true"; version; exit 0 ;;
p ) opt_push="true"; ;;
\? ) echo "Unknown option: -$OPTARG" >&2; exit 1;;
: ) echo "Missing option argument for -$OPTARG" >&2; exit 1;;
* ) echo "Unimplemented option: -$OPTARG" >&2; exit 1;;
esac
done
shift $((OPTIND - 1))
startBranch=$(git rev-parse --abbrev-ref HEAD)
previousBranch=""
while read branch; do
if [ "$startBranch" = "main" ]; then
echo "I'm afraid I can't do that, Dave."
echo "Main contains the latest result including all branches."
echo "This would mess up all checkpoints, which is probably not what you intend."
exit 1;
fi;
if [ "$startBranch" = "$branch" ]; then
previousBranch=$branch
continue;
elif [ "$previousBranch" == "" ]; then
echo "$branch before $startBranch. Ignoring."
continue;
else
git checkout $branch;
git fetch
git rebase
echo "$branch after $startBranch. Merging $previousBranch."
git merge -m "Merging updates from $previousBranch" $previousBranch
if [ "$opt_push" == "true" ]; then
git push
fi;
fi;
done < .lesson-branch-sequence