-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrepo_type
executable file
·49 lines (44 loc) · 1.29 KB
/
repo_type
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
#!/bin/bash
set -eu
test $# -eq 0 && set .
hg_default_repo() {
local repo="$1"
local uri
uri="$(hg -R $repo path default 2>/dev/null)"
if test -z "$uri"; then
uri='<not saved>'
fi
echo $uri
}
get_repo_type() {
local d="$1"
local repo_type=
if test -d "$d/.hg"; then
repo_type="$repo_type hg ($(hg_default_repo $d))"
fi
if test -d "$d/.git" ; then
repo_type="$repo_type git ($(git --git-dir $d/.git remote -v |
awk '$1=="origin" && $3=="(fetch)" {print $2}'))"
elif test -d "$d/.hg/git"; then
repo_type="$repo_type git ($(git --git-dir $d/.hg/git remote -v |
awk '$1=="origin" && $3=="(fetch)" {print $2}'))"
fi
if test -d "$d/.svn" ; then
repo_type="$repo_type svn ($(svn info $d | awk '/^Repository Root:/ {print $3}'))"
fi
# No repo found yet, move up to parent directory
if test -z "$repo_type"; then
# better test might be if parent is writeable by user
if ! test "$d" == "/"; then
local parent_dir=$(dirname "$(cd "$d"; /bin/pwd)")
repo_type=$(get_repo_type "$parent_dir")
else
repo_type="(not a repo)"
fi
fi
echo $repo_type
}
for d; do
repo_type=$(get_repo_type "$d")
echo "$d is $repo_type"
done