-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgit_list.sh
executable file
·55 lines (47 loc) · 1.46 KB
/
git_list.sh
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
#!/bin/bash
# Check argument
if [ $# -lt 2 ]; then
>&2 echo "Usage: $0 <directory to scan> <output>"
exit 1
fi
# Output file
if [ ! -f $2 ]; then
#create a new empty file
touch $2
else
#delete content of the file, keep only the header
header=$(head -1 $2)
echo $header > $2
fi
input=$1
output=$2
# Process:
# Print all the directory that has `.git` in it
count=0
echo -ne ' Preparing...\r'
gitdirs=$(find $input/ -name ".git") #the slash / at the end of input is important
n=$(echo ${gitdirs} | wc -w)
for i in ${gitdirs}; do
count=$((${count}+1))
progress=$((100*${count}/n))
echo -ne ' Running...('${progress}'%)\r'
PATH=`echo $i | /bin/sed 's,/.git$,,g'`
# update git local database
pushd $PATH > /dev/null 2>&1 &&
/usr/bin/git fetch -tq > /dev/null 2>&1
popd > /dev/null 2>&1 &&
URL=`/bin/grep "url" $i/config | /usr/bin/awk '{print $3}'`
HEADS=$(for j in `/bin/ls $i/refs/heads/`; \
do echo $j:$(/bin/cat $i/refs/heads/$j); \
done)
LATEST_TAGS=$(for j in `/bin/ls $i/refs/tags/ | /usr/bin/sort -r | /usr/bin/head -1`; \
do echo $j:$(/bin/cat $i/refs/tags/$j); \
done)
# Get the date of latest commit in local
pushd $PATH > /dev/null 2>&1 &&
LOCAL_DATE=$(/usr/bin/git log -1 --date=short --pretty=format:%ad)
LATEST_DATE=$(/usr/bin/git log -1 origin/master --date=short --pretty=format:%ad)
popd > /dev/null 2>&1 &&
#echo $PATH,$URL,$HEADS,$LATEST_TAGS;
echo $PATH,$URL,$LOCAL_DATE,$LATEST_DATE >> ${output}
done