-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_git-multi-util.sh
More file actions
114 lines (89 loc) · 3.23 KB
/
_git-multi-util.sh
File metadata and controls
114 lines (89 loc) · 3.23 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
104
105
106
107
108
109
110
111
112
113
114
#!/bin/bash
GIT_UTILS_DEBUG=0
if [ "$GIT_UTILS_PATH" = "" ] ; then
echo "Please set GIT_UTILS_PATH environment variable to include directories to check"
exit 1
fi
function __git_init_parent_dirs() {
local check_connectivity=$1
local orig_pwd=`pwd`
local cache_file=`mktemp`
local unreachable_cache_file=`mktemp`
git_parent_dirs=()
for dir in $(echo $GIT_UTILS_PATH | tr ":" "\n") ; do
cd "$orig_pwd"
cd "$dir"
dir=`pwd -P`
cd "$dir"
for dotgit_dir in $(find $dir -name .git -type d | sort) ; do
cd "$dotgit_dir/.."
if [ $check_connectivity -eq 1 ] ; then
local protocol="`git ls-remote --get-url origin | cut -d: -f 1`"
local repo_url=
local repo_domain=
if [ "$protocol" = "http" -o "$protocol" = "https" ] ; then
repo_url=`git ls-remote --get-url origin`
repo_domain=`echo $repo_url | awk -F/ '{print $3}'`
if [[ $repo_domain == *"@"* ]]; then
repo_domain=`echo $repo_domain | awk -F@ '{print $2}'`
fi
else
protocol="ssh"
repo_url=`git ls-remote --get-url origin | cut -d: -f 1`
if [[ $repo_url == *"@"* ]]; then
repo_domain=`echo $repo_url | awk -F@ '{print $2}'`
else
repo_domain=$repo_url
fi
fi
if [ $GIT_UTILS_DEBUG -eq 1 ] ; then
echo "GIT_UTILS_DEBUG - dir: `pwd`, protocol: $protocol, repo_url: $repo_url, repo_domain: $repo_domain"
fi
# Let's see if our domain is already in our "unreachable" cache file,
# and if so, skip.
if [ `grep "^$repo_domain$" $unreachable_cache_file | wc -l` -eq 1 ] ; then
if [ $GIT_UTILS_DEBUG -eq 1 ] ; then
echo "GIT_UTILS_DEBUG - $repo_domain found in unreachable cache file, skipping"
fi
continue
fi
local is_reachable=1
# Let's see if our domain has yet to be checked, and if not, perform
# the protocol-specific test.
if [ `grep "^$repo_domain$" $cache_file | wc -l` -eq 0 ] ; then
echo $repo_domain >> $cache_file
if [ "$protocol" = "http" -o "$protocol" = "https" ] ; then
if [ $GIT_UTILS_DEBUG -eq 1 ] ; then
echo "GIT_UTILS_DEBUG - Testing HTTPS access for $repo_url"
fi
curl -s --connect-timeout 2 $repo_url > /dev/null
if [ $? -eq 28 ] ; then
is_reachable=0
fi
else
if [ $GIT_UTILS_DEBUG -eq 1 ] ; then
echo "GIT_UTILS_DEBUG - Testing SSH access for $repo_url"
fi
ssh -o ConnectTimeout=2 $repo_url > /dev/null 2>&1
if [ $? -eq 255 ] ; then
is_reachable=0
fi
fi
fi
if [ $is_reachable -eq 0 ] ; then
if [ $GIT_UTILS_DEBUG -eq 1 ] ; then
echo "GIT_UTILS_DEBUG - Putting $repo_domain in unreachable cache file"
fi
echo $repo_domain >> $unreachable_cache_file
continue
fi
fi
git_parent_dirs+=(`pwd`)
done
done
# I am not expected to understand this...
IFS=$'\n' sorted=($(sort <<<"${array[*]}"))
unset IFS
rm -f $cache_file $unreachable_cache_file
cd "$orig_pwd"
}