-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspush-tag.sh
110 lines (73 loc) · 2.19 KB
/
spush-tag.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/bash
# Gather required parameters from user
if [[ -z "$1" ]]; then
echo -e "ERR: Missing required parameters"
echo -e "Usage: spush-tag [tag] [repo-dir(s)]"
exit
fi
dirs=("$@")
currentDir=${PWD}
# Remove repos
if [[ ! -d ~/webiik-repos/cli/ ]]; then
mkdir -p ~/webiik-repos/cli/
fi
if [[ "$#" == 1 ]]; then
# Tag all repos
# List all directories in src/Webiik
for dir in src/*
do
# Remove the trailing "/"
dir=${dir%*/}
# Get everything after the final "/"
dir=${dir##*/}
# Remove existing split repo dir
if [[ -d ~/webiik-repos/cli/${dir} ]]; then
sudo rm -r ~/webiik-repos/cli/${dir}
fi
mkdir ~/webiik-repos/cli/${dir}
cd ~/webiik-repos/cli/${dir}
git init --bare
cd ${currentDir}
git subtree split --prefix=src/${dir} -b ${dir}
git push ~/webiik-repos/cli/${dir} ${dir}:master
cd ~/webiik-repos/cli/${dir}
repo=$(echo ${dir} | perl -pe 's/([a-z]|[0-9])([A-Z])/\1-\2/g')
repo=$(echo ${repo} | tr '[:upper:]' '[:lower:]')
git remote add origin https://github.com/webiik/cli-${repo}.git
git tag ${1}
git push origin master --tags --force
cd ${currentDir}
git branch -D ${dir}
git subtree push --prefix=src/${dir} https://github.com/webiik/cli-${repo}.git master --squash
done
fi
if [[ "$#" > 1 ]]; then
# Tag one or more repos
for dir in "${dirs[@]:1}"
do
# Check if dir exists
if [[ ! -d "src/${dir}" ]]; then
echo -e "🚨ERR: src/${dir} doesn't exist, skipped."
continue
fi
# Remove existing split repo dir
if [[ -d ~/webiik-repos/cli/${dir} ]]; then
sudo rm -r ~/webiik-repos/cli/${dir}
fi
mkdir ~/webiik-repos/cli/${dir}
cd ~/webiik-repos/cli/${dir}
git init --bare
cd ${currentDir}
git subtree split --prefix=src/${dir} -b ${dir}
git push ~/webiik-repos/cli/${dir} ${dir}:master
cd ~/webiik-repos/cli/${dir}
repo=$(echo ${dir} | perl -pe 's/([a-z]|[0-9])([A-Z])/\1-\2/g')
repo=$(echo ${repo} | tr '[:upper:]' '[:lower:]')
git remote add origin https://github.com/webiik/cli-${repo}.git
git tag ${1}
git push origin master --tags --force
cd ${currentDir}
git branch -D ${dir}
git subtree push --prefix=src/${dir} https://github.com/webiik/cli-${repo}.git master --squash
done
fi