-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathget-repo-cur-rev
More file actions
49 lines (39 loc) · 813 Bytes
/
get-repo-cur-rev
File metadata and controls
49 lines (39 loc) · 813 Bytes
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
THIS="get-repo-cur-rev"
exiterr() {
echo -e "$THIS: $@" 1>&2;
exit 1
}
if [ "$1" == "-h" ] || [ "$1" == "--h" ]
then
exiterr "Get the current repository revisions below a base directory.\n\nUSAGE: $THIS [base dir]\n"
fi
fpath="${1:-.}"
while IFS=$'\n' read -r rdir
do
[[ "$rdir" =~ ^(.+/(.+)/)\.(git|hg|svn)$ ]]
tool="${BASH_REMATCH[3]}"
dir="${BASH_REMATCH[1]}"
name="${BASH_REMATCH[2]}"
printf "%s\t%s\t" "$name" "$tool"
case "$tool" in
git)
cd "$dir"
git rev-parse HEAD
cd ..
;;
hg)
cd "$dir"
hg id -i | grep -Eo '[a-f0-9]+'
cd ..
;;
svn)
cd "$dir"
svn info --show-item revision
cd ..
;;
*)
echo "unknown"
;;
esac
done < <(find "$fpath" -mindepth 2 -maxdepth 2 -type d -name ".git" -o -name ".svn" -o -name ".hg" | sort)