-
Notifications
You must be signed in to change notification settings - Fork 4
/
update-repo
59 lines (50 loc) · 1.14 KB
/
update-repo
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
#!/bin/bash
THIS="update-repo"
exiterr() {
echo -e "$THIS: $@" 1>&2;
exit 1
}
if [ "$1" == "-h" ] || [ "$1" == "--h" ]
then
exiterr "Updates all repositories 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\n%s\t%s:\n" "===============================================================================" "$name" "$tool"
case "$tool" in
git)
cd "$dir"
git fetch --all
#git reset --hard HEAD
git reset --hard origin/HEAD
#git rev-parse HEAD
git show -s --format="%n%ci%n%cN (%ce)"
git log -n 1 --oneline --decorate origin/HEAD
cd ..
;;
hg)
cd "$dir"
hg pull
hg update --clean
hg id -i | grep -Eo '[a-f0-9]+'
hg log --limit 1
cd ..
;;
svn)
cd "$dir"
svn revert -R .
svn update
#svn log -r $(svn info --show-item revision)
svn log --limit 1
cd ..
;;
*)
echo "unknown"
;;
esac
done < <(find "$fpath" -mindepth 2 -maxdepth 2 -type d -name ".git" -o -name ".svn" -o -name ".hg" | sort)