-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzukit.sh
More file actions
executable file
·134 lines (115 loc) · 4.12 KB
/
zukit.sh
File metadata and controls
executable file
·134 lines (115 loc) · 4.12 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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/bash
# Retrieve 'zukit.sh' from the repository
# curl 'https://raw.githubusercontent.com/picasso/zukit/master/zukit.sh' > zukit.sh
function message() {
local reset='\033[0m'
local color='\033[2m'
local newline='\n'
local beforeline=''
case "$2" in
'red')
color='\033[1;31m'
;;
'green')
color='\033[0;32m'
;;
'blue')
color='\033[0;34m'
;;
'brown')
color='\033[0;33m'
;;
'bold')
color='\033[1m'
;;
*)
color='\033[2m'
esac
if [ "$3" == false ]; then
newline=''
elif [ "$3" == true ]; then
beforeline='\n'
fi
echo "$beforeline$color$1$reset$newline"
}
function check_remote() {
local existed=$(git remote)
if [[ $existed =~ "zukit" ]]; then
# remove if remote already exists)
message 'Previous remote "zukit" was removed!' 'red' false
git remote rm zukit
fi
}
function has_remote() {
local existed=$(git remote)
if [[ $existed =~ 'zukit' ]]; then
echo "1"
else
echo "0"
fi
}
#------------------------------------------------------------------------------#
message "*** Init Zukit subtree ***" 'brown' true
if [ ! -d .git ]; then
message " No a git repository found!" 'red'
exit 1
fi
reinit=false
# Check if zukit subtree has already been installed
if [[ -d 'zukit' && $(has_remote) == "1" ]]; then
message 'It looks like you already have "zukit" subtree initialized.' 'brown' false
message 'Do you want to remove it and reinitialize it from scratch? [Y/n]' 'brown' false
read -n1 choice
echo '\n'
if [[ $choice == 'Y' ]]; then
reinit=true
message '### Removing the previous remote "zukit"...' 'red' false
git remote rm zukit
message '### Removing the previous "zukit" subtree...' 'red'
git rm -r zukit
rm -rf zukit
git add .
git commit -am 'after removing previous Zukit subtree'
echo '\n'
else
message '### Try using "git subtree pull..." to update.' 'blue' true
exit 0
fi
fi
# initialize remote
message "### Initialize Zukit remote..." 'blue' false
git remote add -f zukit https://github.com/picasso/zukit.git &> /dev/null
# check if local repository has changes
if [[ `git status --porcelain` ]]; then
message "### Commit all changes before adding Zukit subtree..." 'blue' true
git add .
git commit -am 'before adding Zukit subtree'
fi
# add subtree
message "### Adding Zukit subtree..." 'blue' true
git subtree add --prefix=zukit zukit master --squash
git commit --amend -m 'Zukit subtree initialized'
# enable sparse-checkout
message "### Enable and configure sparse-checkout..." 'blue' true
git config core.sparsecheckout true
# configure sparse-checkout by specifying what files are not included
echo '*\n!zukit/src/**\n!zukit/*.json\n!zukit/*.md\n!zukit/lang/*.pot\n!zukit/.*' >> .git/info/sparse-checkout
# read tree information into the index and update working tree
git read-tree -mu HEAD
# add 'export-ignore' to .gitattributes
message "### Configure git archive..." 'blue'
echo '\n# Zukit ignore stuff\n\nzukit/src export-ignore\nzukit/package.json export-ignore' >> .gitattributes
echo 'zukit/package-lock.json export-ignore\nzukit/*.md export-ignore\nzukit/*.sh export-ignore' >> .gitattributes
echo 'zukit/*.pot export-ignore\nzukit/.* export-ignore\nzukit/translate-2-json.mjs export-ignore' >> .gitattributes
echo 'zukit/*.cjs export-ignore\nzukit/eslint.config.js export-ignore' >> .gitattributes
# mission complete
message "### done!" 'green'
if [[ $reinit == true ]]; then
message "### Don't forget to check '.gitattributes' and '.git/info/sparse-checkout' and remove duplicate lines!" 'red'
fi
message "================================" 'dim' false
message "*** How to work with subtree ***" 'bold'
message "# pull updates from Zukit" 'dim' false
message "git subtree pull --prefix=zukit zukit master --squash -m 'Zukit updated'" 'blue'
message "# remove Zukit subtree" 'dim' false
message "git rm -r zukit" 'blue'