-
Notifications
You must be signed in to change notification settings - Fork 10
/
git-find-repos
executable file
·57 lines (47 loc) · 1.35 KB
/
git-find-repos
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
#!/bin/bash
set -e
usage() {
echo "USAGE: git-find-repos [-h | --help] [-d | --dirty] <path>"
exit 1
}
dirty=
path=$(pwd)
realargs="$@"
while [ $# -gt 0 ]; do
case "$1" in
-h | --help)
usage
;;
-d | --dirty)
dirty=1
;;
*)
path=$1
;;
esac
shift
done
set -- $realargs
COUNTER=0
DIRTYCOUNTER=0
start_time=`date +%s`
if [ -n "$dirty" ]; then
while IFS= read -r -d $'\0' line; do
COUNTER=$(( $COUNTER + 1 ))
tmpPath=$(dirname ${line})
cd ${tmpPath}
gitStatus=$(git status -uall -s 2>/dev/null)
gitUnpushedCommits=$(git --no-pager log --graph --branches --not --remotes --oneline 2>/dev/null)
if [ -n "$gitStatus" ] || [ -n "$gitUnpushedCommits" ]; then
DIRTYCOUNTER=$(( $DIRTYCOUNTER + 1 ))
echo "[$DIRTYCOUNTER.] $tmpPath"
fi
done < <(find $path -type d -name ".git" -print0 2>/dev/null)
echo "Found $DIRTYCOUNTER changed repos among $COUNTER git repositories under $path in $(expr `date +%s` - $start_time) seconds"
else
while IFS= read -r -d $'\0' line; do
COUNTER=$(( $COUNTER + 1 ))
echo "[$COUNTER.] ${line}"
done < <(find $path -type d -name ".git" -print0 2>/dev/null)
echo "Found $COUNTER git repositories under $path in $(expr `date +%s` - $start_time) seconds"
fi