-
Notifications
You must be signed in to change notification settings - Fork 0
/
submodule_restore.sh
executable file
·54 lines (48 loc) · 1.22 KB
/
submodule_restore.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
#!/bin/bash
#set some values
set -e
#Check params
force=false
initGit=false
while getopts ":cp" opt; do :
case $opt in
#TODO f doesn't work?!
c)
force=true;;
# i)
# initGit=true;;
esac
done
########################################
################DO STUFF################
########################################
#(re)-init git if wanted
#if [ "$initGit" = true ]; then
rm -rf .git
git init
#fi
#TODO why is a tempfile is needed?
git config -f .gitmodules --get-regexp '^submodule\..*\.path$' > tempfile
#read 3 lines etc.
while read -u 3 path_key path
do
url_key=$(echo $path_key | sed 's/\.path/.url/')
url=$(git config -f .gitmodules --get "$url_key")
#TODO Check if directory exists, if not ignore force
if [ "$force" = false ];then
read -p "Are you sure you want to delete $path and re-initialize as a new submodule? " yn
case $yn in
[Yy]* );;
[Nn]* ) continue;;
* ) echo "Please answer yes or no."
#TODO doesn't repeat loop
continue;;
esac
fi
#create submodule
#TODO it terminates if submodule has been added before
rm -rf $path
git submodule add $url $path
echo "$path has been initialized"
done 3<tempfile
rm tempfile