-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetSubmodules.sh
More file actions
55 lines (48 loc) · 1.66 KB
/
getSubmodules.sh
File metadata and controls
55 lines (48 loc) · 1.66 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
#!/usr/bin/env bash
#
# To Use:
# Pass no arguments and it will just return branches and commits
# Pass any argument and it will git fetch and ask for confirmation before git pull on repos with a branch checked out
# Replace with absolute directory to folder tracked by git
rn="/home/user/folder/"
# Repositories and submodules (relative paths from $rn)
dirs=("submodule1" "submodule1/other_sub")
declare -i num=1
echo ""
for dir in ${dirs[@]}
do
cd "$rn$dir"
status=$(git status)
arrIN=(${status//changes/ })
if [[ $status == *"HEAD detached"* ]]; then
echo -e "$dir : \033[32m${arrIN[3]}\033[0m"
else
if [[ "$#" -eq 1 ]]; then
git fetch
status=$(git status)
fi
if [[ $status != *"up to date"* ]]; then
echo -e "$dir : \033[31m${arrIN[2]} -> NEEDS UPDATED\033[0m"
if [[ "$#" -eq 1 ]]; then
echo "Do you wish pull this submodule?"
select yn in "Yes" "No"; do
case $yn in
Yes ) git pull; break;; #git submodule update --init --recursive; break;;
No ) echo "Not pulling"; break;;
esac
done
fi
else
hash=$(git log -n 1 --pretty=format:"%H" | cut -c 1-7)
echo -e "$dir : \033[33m${arrIN[2]}\033[0m at commit \033[32m${hash}\033[0m"
fi
fi
# Change to seprate individual repos if desired
if [[ $num -eq 1 ]]; then
echo ""
echo "------------------------------------------------------------------------------------------------------"
echo ""
fi
((num++))
done
echo ""