aboutsummaryrefslogtreecommitdiffstats
path: root/utils/blame2humantest.bash
blob: 259988f5e57fba287603522b575fd5ffed73faf0 (plain) (blame)
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
#!/bin/bash

set -e

repo=`git remote show origin | grep Fetch | cut -d' ' -f5`
branch="master"
if [ "$#" -eq 1 ] ; then
    commit=`git log | head -1 | cut -d' ' -f2`
    path=$1
elif [ "$#" -eq 2 ] ; then
    commit=$1
    path=$2
else
    echo "bad number of parameters" > /dev/stderr
    echo > /dev/stderr
    echo "    try with: [commit] path" > /dev/stderr
    exit
fi

blames=`git blame --root $path | cut -d' ' -f1`
declare -a blame
i=0
for shortBlame in $blames ; do
    blame[$i]=`git show $shortBlame | head -1 | cut -d' ' -f2`
    i=`expr $i + 1`
done

# some remotes have the .git, other don't,
# repoDot makes sure all have
repoDot="${repo%.git}.git"

echo -e "\t{\"${repoDot}\", \"${branch}\", \"${commit}\", \"${path}\", concat(&[]string{},"
prev=""
count=1
for i in ${blame[@]} ; do
    if [ "${prev}" == "" ] ; then
        prev=$i
    elif [ "$prev" == "$i" ] ; then
        count=`expr $count + 1`
    else
        echo -e "\t\trepeat(\"${prev}\", $count),"
        count=1
        prev=$i
    fi
done
echo -e "\t\trepeat(\"${prev}\", $count),"
echo -e "\t)},"