-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitlist.sh
140 lines (127 loc) · 2.01 KB
/
gitlist.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/bash
_level=3
while test $# != 0; do
case "$1" in
-v)
_debug=1
shift
_level=$1
shift
;;
-n)
_no_remotes=1
shift
;;
-u)
_update=1
_no_remotes=1
shift
;;
-p)
_path=1
shift
;;
-pp)
_fullpath=1
_path=1
shift
;;
*)
break
;;
esac
done
dbg() {
if [ "$1" -lt "$_level" ]; then
return 0
fi
case "$1" in
1)
lvl='debug'
clr='\e[0;36m'
;;
2)
lvl='info'
clr='\e[0;32m'
;;
3)
lvl='warn'
clr='\e[0;33m'
;;
4)
lvl='error'
clr='\e[0;31m'
;;
esac
if [ -z $_debug ]; then
return 0
fi
>&2 echo -e "$clr$(printf %-9s [$lvl])$2\e[0m"
}
git_at_to_https() {
url=$1
if [ ${1:0:4} == 'git@' ]; then
url_right=`echo ${1:4} | sed -e 's/:/\//'`
url="https://${url_right}"
fi
echo $url
}
wd=${1:-`pwd`}
wd=$(realpath $wd)
dbg 1 "root dir $wd"
_IFS=$IFS
IFS=$(echo -en "\n\b")
used=''
pushd "$wd" > /dev/null
#for d in $(find ~- -type d -not -name ".git"); do
for d in $(find . -type d -not -name ".git"); do
if [ ! -z $used ]; then
if [[ "$d" =~ ^$used ]]; then
dbg 1 "still in repo, skipping $d"
continue
else
used=''
fi
fi
pushd "$d" > /dev/null
if [ $(git rev-parse HEAD 2> /dev/null) ]; then
used=$d
dbg 2 "found repo $d"
if [ ! -z $_update ]; then
git remote update
continue
fi
if [ ! -z $_no_remotes ]; then
echo $d
continue
fi
origin=`git remote -v | awk '$1 ~ /origin/ && $3 == "(fetch)" { print $2; }'`
if [[ $origin =~ ^ssh ]]; then
dbg 4 "skipping ssh url $origin"
popd > /dev/null
continue
elif [ -z "$origin" ]; then
dbg 4 "origin missing from repo $d"
dbg 4 "available remotes $(git remote -v)"
popd > /dev/null
continue
fi
t=$origin
origin=$(git_at_to_https $origin)
if [ "$t" != "$origin" ]; then
dbg 3 "changed $t -> $origin"
fi
if [ ! -z $_path ]; then
if [ -z $_fullpath ]; then
p=${d/$wd}
else
p=$wd/${d:2}
fi
echo -e "$origin\t$p"
else
echo "$origin"
fi
fi
popd > /dev/null
done
popd > /dev/null