ENH: Update FreeFOAM contributions to GPL v3
[freefoam.git] / data / utilities / updateChangeLog
bloba6df353c274b2a3a0db6dc30973e8164b8bafaa9
1 #!/bin/sh
2 #-------------------------------------------------------------------------------
3 # ______ _ ____ __ __
4 # | ____| _| |_ / __ \ /\ | \/ |
5 # | |__ _ __ ___ ___ / \| | | | / \ | \ / |
6 # | __| '__/ _ \/ _ ( (| |) ) | | |/ /\ \ | |\/| |
7 # | | | | | __/ __/\_ _/| |__| / ____ \| | | |
8 # |_| |_| \___|\___| |_| \____/_/ \_\_| |_|
10 # FreeFOAM: The Cross-Platform CFD Toolkit
12 # Copyright (C) 2008-2012 Michael Wild <themiwi@users.sf.net>
13 # Gerber van der Graaf <gerber_graaf@users.sf.net>
14 #-------------------------------------------------------------------------------
15 # License
16 # This file is part of FreeFOAM.
18 # FreeFOAM is free software: you can redistribute it and/or modify it
19 # under the terms of the GNU General Public License as published by the
20 # Free Software Foundation, either version 3 of the License, or (at your
21 # option) any later version.
23 # FreeFOAM is distributed in the hope that it will be useful, but WITHOUT
24 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
25 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26 # for more details.
28 # You should have received a copy of the GNU General Public License
29 # along with FreeFOAM. If not, see <http://www.gnu.org/licenses/>.
31 # Script
32 # updateChangeLog [-h|--help] [-s|--since <version>] <version>
34 # Description
35 # Updates the ChangeLog file with data from the GIT log.
37 # -h
38 # --help Print a help message
39 # -s <version>
40 # --since <version> Instead of searching the latest annotated tag
41 # beginning with a `v', use the history since tag
42 # v<version>.
43 # <version> The version to mention in the heading.
45 #------------------------------------------------------------------------------
47 SUBDIRECTORY_OK=Yes
49 OPTIONS_SPEC="\
50 updateChangeLog [options] <version>
52 Generates entries in the ChangeLog file for version <version> with data from
53 the GIT version control.
55 The --since <version> option requires that a git tree-ish object with the name
56 v<version> exists (i.e. a tag named e.g. v0.1.0).
58 s,since= Consider history since v<version> tag instead of latest v* tag."
60 . "$(git --exec-path)/git-sh-setup"
62 cd_to_toplevel
64 FILE=ChangeLog
65 SINCE=
66 VERSION=
68 while [ $# -gt 0 ]; do
69 case "$1" in
70 -s|--since)
71 SINCE="v$2"
72 shift 2
74 --)
75 VERSION="$2"
76 shift 2
77 break
79 esac
80 done
82 if [ -z "$VERSION" ]; then
83 die "Version argument is required"
86 if ! [ -w "$FILE" ]; then
87 die "The file '$FILE' does not exist or is not writeable"
90 if [ -z "$SINCE" ]; then
91 SINCE="$(git describe --match 'v[0-9].[0-9].[0-9]*' --abbrev=0 2>/dev/null)"
92 stat=$?
93 if [ $stat -ne 0 ]; then
94 die "Failed to find latest annotated tag matching 'v[0-9].[0-9].[0-9]*'"
98 # determine whether SINCE is an ancestor of HEAD
99 git merge-base "$SINCE" HEAD >/dev/null 2>&1 || \
100 die "Tag v$SINCE does not exist or is not an ancestor of HEAD"
102 echo "Updating $FILE with changes from $SINCE to $VERSION"
104 # write log entries to a temporary file
105 tmp1=$(mktemp)
106 tmp2=$(mktemp)
107 trap 'rm -f $tmp1 $tmp2 2>/dev/null; exit 0' EXIT TERM INT
108 git shortlog -w --format='* %s' "$SINCE"..HEAD | \
109 grep -v 'Merge branch' | sed 's|[0-9]):$|&:|' > "$tmp1"
111 awk '
112 BEGIN {dosub=1}
113 /^Changes in {project}/ && dosub {
114 header = "Changes in {project} '$VERSION'";
115 print header;
116 print gensub(/./, "-", "g", header);
117 system("cat '$tmp1'");
118 dosub=0;
120 {print $0}' $FILE > $tmp2
122 mv $tmp2 $FILE
124 # ------------------------- vim: set sw=3 sts=3 et: --------------- end-of-file