-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathchangelog.sh
executable file
·89 lines (79 loc) · 1.97 KB
/
changelog.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env bash
function show_help() {
echo "Usage: changelog.sh [options]"
echo "Generates a changelog from git history"
echo
echo "Format:"
echo "YYYY-MM-DD: commit subject [committer name]"
echo
echo "Options:"
echo "-v Verbose output (i.e. include full commit messages)"
echo "-r <since>..<until> Range of commits to query, see \`git log\` for more"
echo " defaults to most recent version tag (i.e. \"`default_range`\")"
echo "-b Add a banner to the output"
echo "-p Specify the working directory of the repository (default: \"$repository_path\")"
}
verbose=0
range_parameter=0
banner=0
repository_path="./"
function default_range() {
local latest_version_tag=`cd $repository_path && git describe --abbrev=0 --tags | tail -1`
# a ".." range tag causes the `git log` command to fail
if [ -z "$latest_version_tag" ]; then
echo ''
else
echo "$latest_version_tag.."
fi
}
while getopts "h?bvp:r:" opt; do
case $opt in
h|\?)
show_help
exit 0
;;
b )
banner=1
;;
v )
verbose=1
;;
r )
range_parameter=$OPTARG
;;
p )
repository_path=$OPTARG
;;
esac
done;
function get_range() {
if [ $range_parameter = 0 ]; then
default_range
else
echo $range_parameter
fi
}
range=`get_range`
function get_format() {
# Subject/author line wraps at 80 characters, no padding
local format_subject_author="%w(80,0,0)%ad: %s [%cN]%n"
if [ $verbose = 0 ]; then
echo "tformat:$format_subject_author"
else
echo "tformat:$format_subject_author%n%w(72,4,4)%b"
fi
}
pretty_format=`get_format`
function changelog() {
# Get a list of all commits for the ranger that were not merges
cd $repository_path && git log $range --no-merges --pretty="$pretty_format" --date=short
}
function main() {
if [ $banner = 1 ]; then
echo $range
echo $range | sed -e 's/./-/g'
echo ''
fi
changelog
}
main