-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmodule.sh
More file actions
103 lines (93 loc) · 2.56 KB
/
submodule.sh
File metadata and controls
103 lines (93 loc) · 2.56 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
#!/bin/bash
show_help() {
cat << EOF
Usage: ${0##*/} COMMAND
Available commands are:
init: Initialize the git submodule - 'git submodule update --init --recursive --remote'
add PATH: Add a new submodule at the specified path, with the branch defaulting to 'master'. Pass branch name as third argument if different.
del PATH: Delete the submodule at the specified path
Examples:
${0##*/} info
${0##*/} init
${0##*/} update
${0##*/} add ../../submodule
${0##*/} add ../../submodule branchname
${0##*/} del submodule
${0##*/} switch submodule develop
EOF
}
command=$1
path=$2
branch=$3
if [ -z "$command" ]; then
show_help
exit 1
fi
case $command in
info)
git submodule
cat .gitmodules
;;
init)
git submodule update --init --recursive --remote
;;
update)
git submodule update --recursive --remote
;;
add)
if [ -n "$path" ]; then
if [ -z "$branch" ]; then
git submodule add --force "$path"
else
git submodule add -b "$branch" "$path"
fi
git submodule update --init --recursive --remote
#git status
cat .gitmodules
git add "$path"
git add .gitmodules
git commit -m "Added submodule: $path"
git push
else
echo "Path is required for add command"
fi
;;
switch)
if [ -n "$path" ]; then
cat .gitmodules
cd "$path"
switch "$branch"
git pull
cd ..
git submodule set-branch -b "$branch" "$path"
git submodule sync
git submodule update --init --recursive --remote
cat .gitmodules
git add "$path"
git add .gitmodules
git commit -m "Switched branch: '$branch' in submodule: '$path'"
git push
else
echo "Path is required for add command"
fi
;;
del)
if [ -n "$path" ]; then
git submodule deinit -f -- "$path"
rm -rf ".git/modules/$path"
git rm -f "$path"
cat .gitmodules
git add "$path"
git add .gitmodules
git commit -m "Deleted submodule: $path"
git push
else
echo "Path is required for del command"
fi
;;
*)
echo "Invalid command"
show_help
exit 1
;;
esac