-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmastertomain.sh
executable file
·92 lines (80 loc) · 2.5 KB
/
mastertomain.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
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env bash
#
# SPDX-License-Identifier: Apache-2.0
set -eu
function create_main() {
echo "creating ${MAIN}..."
git checkout master
git pull origin master
git checkout -b "${MAIN}"
echo "done"
echo ""
}
function find_master() {
git grep -w -q master
}
function delete_master() {
git pull
git branch -d master
git push origin :master
}
git checkout master
function is_dirty() {
git add .
git restore --staged mastertomain.sh
! git diff-index --quiet HEAD
}
if is_dirty; then
echo "Hey! I found uncommitted changes in your repo. Please commit/stage/nuke your changes and try again."
exit 1
fi
MAIN=${MAIN:-main}
echo "Welcome! I will help you convert your master branch to be called ${MAIN}."
echo "Black Lives Matter!"
echo "Some steps are automated, others you will need to do manually. I'll prompt you for each manual step,"
echo "after which you can come back here and continue."
echo ""
echo "First, some automated steps..."
echo ""
create_main
if find_master; then
echo "I found some uses of the word 'master' in your code. I'm going to present them to you one at a time"
echo "for you to review and accept or deny. Please review them carefully, because I will commit the changes"
echo "you accept. Hit enter to continue"
echo ""
read -r
# shellcheck disable=SC2044
for filename in $(find . -type f -name "*" ! -path './.git/*' ! -name 'mastertomain.sh' ! -path './vendor/*'); do
vim -c "%s/master/${MAIN}/gc" -c "wq" "${filename}"
done
echo ""
echo "Phew! All done!"
echo ""
if is_dirty; then
echo "Committing changes..."
git commit -m "convert master to ${MAIN}"
else
echo "No changes made."
fi
echo "done"
echo ""
fi
echo "Pushing ${MAIN} to github..."
git push --set-upstream origin "${MAIN}"
echo "done"
echo ""
echo "Now I'm going to walk you through a series of manual steps, after I'll do a last few scripted steps."
echo ""
echo "Go to your repo on GitHub. Under settings => branches, update any branch protections. Hit enter to continue."
read -r
echo "Still on GitHub, look under Pull requests. Update any open pull requests to use ${MAIN} as the base. Hit enter to continue."
read -r
echo "Update any *external* dependencies, e.g, concourse. Hit enter to continue."
read -r
echo "Back on Github under settings => branches, update the default branch to ${MAIN}. Hit enter to continue."
read -r
echo "Deleting master (drumroll please!)..."
delete_master
echo "done!"
echo ""
echo "Thanks for making your project a safer and more inclusive environment."