-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-log-markdown.sh
74 lines (54 loc) · 2.13 KB
/
git-log-markdown.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
#
# ******************************************************************************
# @file git-log-markdown.sh
# @brief Script which generates a markdown file for git history between two
# ids including the hitsory of submodules
# ******************************************************************************
#Include '_common.sh'
if [ ${BASH_SOURCE+set} ]; then
source "$(dirname ${BASH_SOURCE[0]})/_common.sh"
else
source "$(dirname $0)/_common.sh"
fi
#-------------------------------------------------------------------------------
script_begin "git-log-markdown.sh"
#-------------------------------------------------------------------------------
if [ $# -ne 3 ]; then
echo "Usage: $0 [from] [to] [output]"
exit 1
fi
arg_from="$1"
arg_to="$2"
arg_output=$(realpath "$3")
#-------------------------------------------------------------------------------
cd ${CONFIG_GIT_PROJECT_ROOT_PATH}
git_project_name=$(basename ${CONFIG_GIT_PROJECT_ROOT_PATH})
echo "Project ${git_project_name}: ${arg_from} -> ${arg_to}"
echo "# ${git_project_name}" > ${arg_output}
#Log of master
#See https://git-scm.com/docs/pretty-formats
git log ${arg_from}..${arg_to} --pretty=format:"## %h%n%B" >> ${arg_output}
echo "" >> ${arg_output}
#Get list of submodule names
#See https://stackoverflow.com/questions/12641469/list-submodules-in-a-git-repository
submodule_paths=$(git config --file .gitmodules --get-regexp path | awk '{ print $2 }')
for name in ${submodule_paths}; do
from_hash=$(git rev-parse ${arg_from}:${name})
to_hash=$(git rev-parse ${arg_to}:${name})
if [ ${from_hash} == ${to_hash} ]; then
continue
fi
echo "Submodule ${name}: ${from_hash} -> ${to_hash}"
#Enter the submodule's directory
cd ${name}
echo "" >> ${arg_output}
echo "---" >> ${arg_output}
echo "# ${name}" >> ${arg_output}
#Get the submodules log
git log ${from_hash}..${to_hash} --pretty=format:"## %h%n%B" >> ${arg_output}
#Return to project root
cd ${CONFIG_GIT_PROJECT_ROOT_PATH}
done
#-------------------------------------------------------------------------------
script_exit