Mercurial > gnulib
annotate build-aux/git-version-gen @ 40208:f746878ee9be
git-version-gen: fix --version copyright year
* build-aux/git-version-gen, build-aux/move-if-change (version):
--version output copyright year is now taken from script year,
so that it no longer needs to be updated by hand.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Tue, 05 Mar 2019 15:05:33 -0800 |
parents | b06060465f09 |
children |
rev | line source |
---|---|
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
1 #!/bin/sh |
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
2 # Print a version string. |
19553
f5dae61a17f4
maint: write-file-hooks -> before-save-hook
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
3 scriptversion=2018-03-07.03; # UTC |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
4 |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
19553
diff
changeset
|
5 # Copyright (C) 2007-2019 Free Software Foundation, Inc. |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
6 # |
11986
ff87a690cd47
Fix copyright header in build-aux scripts.
Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
parents:
9877
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
8 # it under the terms of the GNU General Public License as published by |
11986
ff87a690cd47
Fix copyright header in build-aux scripts.
Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
parents:
9877
diff
changeset
|
9 # the Free Software Foundation; either version 3 of the License, or |
ff87a690cd47
Fix copyright header in build-aux scripts.
Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
parents:
9877
diff
changeset
|
10 # (at your option) any later version. |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
11 # |
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
15 # GNU General Public License for more details. |
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
16 # |
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
17 # You should have received a copy of the GNU General Public License |
19190 | 18 # along with this program. If not, see <https://www.gnu.org/licenses/>. |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
19 |
19192
d86e08b1f555
all: Replace many more http URLs by https URLs. Update stale URLs.
Bruno Haible <bruno@clisp.org>
parents:
19190
diff
changeset
|
20 # This script is derived from GIT-VERSION-GEN from GIT: https://git-scm.com/. |
9452
595a77da32de
git-version-gen: sync from coreutils.
Jim Meyering <meyering@redhat.com>
parents:
9175
diff
changeset
|
21 # It may be run two ways: |
9677
54e86898dd7d
* build-aux/git-version-gen: Use "git status", not "git-status".
Jim Meyering <meyering@redhat.com>
parents:
9452
diff
changeset
|
22 # - from a git repository in which the "git describe" command below |
9452
595a77da32de
git-version-gen: sync from coreutils.
Jim Meyering <meyering@redhat.com>
parents:
9175
diff
changeset
|
23 # produces useful output (thus requiring at least one signed tag) |
9748
c0c8409cb7a2
* build-aux/git-version-gen: Adjust a comment and the Usage string.
Jim Meyering <meyering@redhat.com>
parents:
9719
diff
changeset
|
24 # - from a non-git-repo directory containing a .tarball-version file, which |
9677
54e86898dd7d
* build-aux/git-version-gen: Use "git status", not "git-status".
Jim Meyering <meyering@redhat.com>
parents:
9452
diff
changeset
|
25 # presumes this script is invoked like "./git-version-gen .tarball-version". |
9452
595a77da32de
git-version-gen: sync from coreutils.
Jim Meyering <meyering@redhat.com>
parents:
9175
diff
changeset
|
26 |
9869 | 27 # In order to use intra-version strings in your project, you will need two |
28 # separate generated version string files: | |
29 # | |
30 # .tarball-version - present only in a distribution tarball, and not in | |
31 # a checked-out repository. Created with contents that were learned at | |
32 # the last time autoconf was run, and used by git-version-gen. Must not | |
33 # be present in either $(srcdir) or $(builddir) for git-version-gen to | |
34 # give accurate answers during normal development with a checked out tree, | |
35 # but must be present in a tarball when there is no version control system. | |
36 # Therefore, it cannot be used in any dependencies. GNUmakefile has | |
37 # hooks to force a reconfigure at distribution time to get the value | |
38 # correct, without penalizing normal development with extra reconfigures. | |
39 # | |
40 # .version - present in a checked-out repository and in a distribution | |
41 # tarball. Usable in dependencies, particularly for files that don't | |
42 # want to depend on config.h but do want to track version changes. | |
43 # Delete this file prior to any autoconf run where you want to rebuild | |
44 # files to pick up a version string change; and leave it stale to | |
45 # minimize rebuild time after unrelated changes to configure sources. | |
46 # | |
15511
52b887a92a8c
git-version-gen: correct the advice in a comment
Jim Meyering <meyering@redhat.com>
parents:
15492
diff
changeset
|
47 # As with any generated file in a VC'd directory, you should add |
52b887a92a8c
git-version-gen: correct the advice in a comment
Jim Meyering <meyering@redhat.com>
parents:
15492
diff
changeset
|
48 # /.version to .gitignore, so that you don't accidentally commit it. |
52b887a92a8c
git-version-gen: correct the advice in a comment
Jim Meyering <meyering@redhat.com>
parents:
15492
diff
changeset
|
49 # .tarball-version is never generated in a VC'd directory, so needn't |
52b887a92a8c
git-version-gen: correct the advice in a comment
Jim Meyering <meyering@redhat.com>
parents:
15492
diff
changeset
|
50 # be listed there. |
9869 | 51 # |
52 # Use the following line in your configure.ac, so that $(VERSION) will | |
53 # automatically be up-to-date each time configure is run (and note that | |
54 # since configure.ac no longer includes a version string, Makefile rules | |
55 # should not depend on configure.ac for version updates). | |
56 # | |
57 # AC_INIT([GNU project], | |
58 # m4_esyscmd([build-aux/git-version-gen .tarball-version]), | |
59 # [bug-project@example]) | |
60 # | |
61 # Then use the following lines in your Makefile.am, so that .version | |
15492
b54bff314db1
git-version-gen: document that EXTRA_DIST must include .version
Iain Nicol <iain@iainnicol.com>
parents:
14372
diff
changeset
|
62 # will be present for dependencies, and so that .version and |
b54bff314db1
git-version-gen: document that EXTRA_DIST must include .version
Iain Nicol <iain@iainnicol.com>
parents:
14372
diff
changeset
|
63 # .tarball-version will exist in distribution tarballs. |
9869 | 64 # |
15492
b54bff314db1
git-version-gen: document that EXTRA_DIST must include .version
Iain Nicol <iain@iainnicol.com>
parents:
14372
diff
changeset
|
65 # EXTRA_DIST = $(top_srcdir)/.version |
9869 | 66 # BUILT_SOURCES = $(top_srcdir)/.version |
67 # $(top_srcdir)/.version: | |
68 # echo $(VERSION) > $@-t && mv $@-t $@ | |
69 # dist-hook: | |
70 # echo $(VERSION) > $(distdir)/.tarball-version | |
71 | |
16082
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
72 |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
73 me=$0 |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
74 |
40208
f746878ee9be
git-version-gen: fix --version copyright year
Paul Eggert <eggert@cs.ucla.edu>
parents:
40057
diff
changeset
|
75 year=`expr "$scriptversion" : '\([^-]*\)'` |
16082
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
76 version="git-version-gen $scriptversion |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
77 |
40208
f746878ee9be
git-version-gen: fix --version copyright year
Paul Eggert <eggert@cs.ucla.edu>
parents:
40057
diff
changeset
|
78 Copyright $year Free Software Foundation, Inc. |
16082
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
79 There is NO warranty. You may redistribute this software |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
80 under the terms of the GNU General Public License. |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
81 For more information about these matters, see the files named COPYING." |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
82 |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
83 usage="\ |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
84 Usage: $me [OPTION]... \$srcdir/.tarball-version [TAG-NORMALIZATION-SED-SCRIPT] |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
85 Print a version string. |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
86 |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
87 Options: |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
88 |
17711
bbf6398214e1
git-version-gen: improve option descriptions
Alfred M. Szmidt <ams@gnu.org>
parents:
17576
diff
changeset
|
89 --prefix PREFIX prefix of git tags (default 'v') |
bbf6398214e1
git-version-gen: improve option descriptions
Alfred M. Szmidt <ams@gnu.org>
parents:
17576
diff
changeset
|
90 --fallback VERSION |
bbf6398214e1
git-version-gen: improve option descriptions
Alfred M. Szmidt <ams@gnu.org>
parents:
17576
diff
changeset
|
91 fallback version to use if \"git --version\" fails |
16083
1b52ba2f7e83
git-version-gen: Add --prefix.
Simon Josefsson <simon@josefsson.org>
parents:
16082
diff
changeset
|
92 |
16082
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
93 --help display this help and exit |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
94 --version output version information and exit |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
95 |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
96 Running without arguments will suffice in most cases." |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
97 |
16706
bd179cf2c9ea
git-version-gen: don't let "prefix" envvar cause trouble
Andreas Oberritter <obi@opendreambox.org>
parents:
16234
diff
changeset
|
98 prefix=v |
17245
179b150e5256
git-version-gen: add --fallback option to use if git is not present
Peter Rosin <peda@lysator.liu.se>
parents:
16706
diff
changeset
|
99 fallback= |
16706
bd179cf2c9ea
git-version-gen: don't let "prefix" envvar cause trouble
Andreas Oberritter <obi@opendreambox.org>
parents:
16234
diff
changeset
|
100 |
16082
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
101 while test $# -gt 0; do |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
102 case $1 in |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
103 --help) echo "$usage"; exit 0;; |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
104 --version) echo "$version"; exit 0;; |
18311
79b2ca5b5982
git-version-gen: avoid undefined shift
Paul Eggert <eggert@cs.ucla.edu>
parents:
18195
diff
changeset
|
105 --prefix) shift; prefix=${1?};; |
79b2ca5b5982
git-version-gen: avoid undefined shift
Paul Eggert <eggert@cs.ucla.edu>
parents:
18195
diff
changeset
|
106 --fallback) shift; fallback=${1?};; |
16082
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
107 -*) |
16234
f9b906545e2f
Use ', not `, for quoting output.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
108 echo "$0: Unknown option '$1'." >&2 |
f9b906545e2f
Use ', not `, for quoting output.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
109 echo "$0: Try '--help' for more information." >&2 |
16082
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
110 exit 1;; |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
111 *) |
17246
7d2aa4fc02ab
git-version-gen: avoid test -z portability glitch
Eric Blake <eblake@redhat.com>
parents:
17245
diff
changeset
|
112 if test "x$tarball_version_file" = x; then |
16082
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
113 tarball_version_file="$1" |
17246
7d2aa4fc02ab
git-version-gen: avoid test -z portability glitch
Eric Blake <eblake@redhat.com>
parents:
17245
diff
changeset
|
114 elif test "x$tag_sed_script" = x; then |
16082
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
115 tag_sed_script="$1" |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
116 else |
16234
f9b906545e2f
Use ', not `, for quoting output.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
117 echo "$0: extra non-option argument '$1'." >&2 |
16082
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
118 exit 1 |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
119 fi;; |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
120 esac |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
121 shift |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
122 done |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
123 |
17246
7d2aa4fc02ab
git-version-gen: avoid test -z portability glitch
Eric Blake <eblake@redhat.com>
parents:
17245
diff
changeset
|
124 if test "x$tarball_version_file" = x; then |
16082
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
125 echo "$usage" |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
126 exit 1 |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
127 fi |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
128 |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
129 tag_sed_script="${tag_sed_script:-s/x/x/}" |
0da13ca4fc80
git-version: Improve command line handling.
Simon Josefsson <simon@josefsson.org>
parents:
15511
diff
changeset
|
130 |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
131 nl=' |
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
132 ' |
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
133 |
13423
ba0385f65ed2
git-version-gen: init shell var to avoid env var influence
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
13379
diff
changeset
|
134 # Avoid meddling by environment variable of the same name. |
ba0385f65ed2
git-version-gen: init shell var to avoid env var influence
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
13379
diff
changeset
|
135 v= |
14372
b894b1646164
git-version-gen: skip "-dirty" check when appropriate
Jim Meyering <meyering@redhat.com>
parents:
14133
diff
changeset
|
136 v_from_git= |
13423
ba0385f65ed2
git-version-gen: init shell var to avoid env var influence
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
13379
diff
changeset
|
137 |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
138 # First see if there is a tarball-only version file. |
9677
54e86898dd7d
* build-aux/git-version-gen: Use "git status", not "git-status".
Jim Meyering <meyering@redhat.com>
parents:
9452
diff
changeset
|
139 # then try "git describe", then default. |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
140 if test -f $tarball_version_file |
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
141 then |
14093
bae3b310c970
git-version-gen: include command name in one more diagnostic
Jim Meyering <meyering@redhat.com>
parents:
14079
diff
changeset
|
142 v=`cat $tarball_version_file` || v= |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
143 case $v in |
14095
a6c3d8a0de24
git-version-gen: convert leading TABs to spaces
Jim Meyering <meyering@redhat.com>
parents:
14094
diff
changeset
|
144 *$nl*) v= ;; # reject multi-line output |
a6c3d8a0de24
git-version-gen: convert leading TABs to spaces
Jim Meyering <meyering@redhat.com>
parents:
14094
diff
changeset
|
145 [0-9]*) ;; |
a6c3d8a0de24
git-version-gen: convert leading TABs to spaces
Jim Meyering <meyering@redhat.com>
parents:
14094
diff
changeset
|
146 *) v= ;; |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
147 esac |
17246
7d2aa4fc02ab
git-version-gen: avoid test -z portability glitch
Eric Blake <eblake@redhat.com>
parents:
17245
diff
changeset
|
148 test "x$v" = x \ |
14095
a6c3d8a0de24
git-version-gen: convert leading TABs to spaces
Jim Meyering <meyering@redhat.com>
parents:
14094
diff
changeset
|
149 && echo "$0: WARNING: $tarball_version_file is missing or damaged" 1>&2 |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
150 fi |
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
151 |
17246
7d2aa4fc02ab
git-version-gen: avoid test -z portability glitch
Eric Blake <eblake@redhat.com>
parents:
17245
diff
changeset
|
152 if test "x$v" != x |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
153 then |
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
154 : # use $v |
13803
112326beb7c3
git-version-gen: do require git-VC'd files in cwd
Jim Meyering <meyering@redhat.com>
parents:
13800
diff
changeset
|
155 # Otherwise, if there is at least one git commit involving the working |
112326beb7c3
git-version-gen: do require git-VC'd files in cwd
Jim Meyering <meyering@redhat.com>
parents:
13800
diff
changeset
|
156 # directory, and "git describe" output looks sensible, use that to |
112326beb7c3
git-version-gen: do require git-VC'd files in cwd
Jim Meyering <meyering@redhat.com>
parents:
13800
diff
changeset
|
157 # derive a version string. |
112326beb7c3
git-version-gen: do require git-VC'd files in cwd
Jim Meyering <meyering@redhat.com>
parents:
13800
diff
changeset
|
158 elif test "`git log -1 --pretty=format:x . 2>&1`" = x \ |
16083
1b52ba2f7e83
git-version-gen: Add --prefix.
Simon Josefsson <simon@josefsson.org>
parents:
16082
diff
changeset
|
159 && v=`git describe --abbrev=4 --match="$prefix*" HEAD 2>/dev/null \ |
14095
a6c3d8a0de24
git-version-gen: convert leading TABs to spaces
Jim Meyering <meyering@redhat.com>
parents:
14094
diff
changeset
|
160 || git describe --abbrev=4 HEAD 2>/dev/null` \ |
13379
d62002e5d9f4
git-version-gen: take a sed script to transform the git tag
Ludovic Courtès <ludo@gnu.org>
parents:
13273
diff
changeset
|
161 && v=`printf '%s\n' "$v" | sed "$tag_sed_script"` \ |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
162 && case $v in |
16084
8c88dd7eb4fb
Fix for last commit.
Simon Josefsson <simon@josefsson.org>
parents:
16083
diff
changeset
|
163 $prefix[0-9]*) ;; |
14095
a6c3d8a0de24
git-version-gen: convert leading TABs to spaces
Jim Meyering <meyering@redhat.com>
parents:
14094
diff
changeset
|
164 *) (exit 1) ;; |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
165 esac |
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
166 then |
9719
ec87f62b97b8
Enable use of older two part flavor 'git describe'.
Bob Proulx <bob@proulx.com>
parents:
9677
diff
changeset
|
167 # Is this a new git that lists number of commits since the last |
ec87f62b97b8
Enable use of older two part flavor 'git describe'.
Bob Proulx <bob@proulx.com>
parents:
9677
diff
changeset
|
168 # tag or the previous older version that did not? |
ec87f62b97b8
Enable use of older two part flavor 'git describe'.
Bob Proulx <bob@proulx.com>
parents:
9677
diff
changeset
|
169 # Newer: v6.10-77-g0f8faeb |
ec87f62b97b8
Enable use of older two part flavor 'git describe'.
Bob Proulx <bob@proulx.com>
parents:
9677
diff
changeset
|
170 # Older: v6.10-g0f8faeb |
19072
770f2cdb2189
git-version-gen: port to Solaris 10
Paul Eggert <eggert@cs.ucla.edu>
parents:
19039
diff
changeset
|
171 vprefix=`expr "X$v" : 'X\(.*\)-g[^-]*$'` || vprefix=$v |
770f2cdb2189
git-version-gen: port to Solaris 10
Paul Eggert <eggert@cs.ucla.edu>
parents:
19039
diff
changeset
|
172 case $vprefix in |
19037
b19c2e91a4c8
git-version-gen: port better to older Git
Paul Eggert <eggert@cs.ucla.edu>
parents:
19036
diff
changeset
|
173 *-*) : git describe is probably okay three part flavor ;; |
b19c2e91a4c8
git-version-gen: port better to older Git
Paul Eggert <eggert@cs.ucla.edu>
parents:
19036
diff
changeset
|
174 *) |
14095
a6c3d8a0de24
git-version-gen: convert leading TABs to spaces
Jim Meyering <meyering@redhat.com>
parents:
14094
diff
changeset
|
175 : git describe is older two part flavor |
a6c3d8a0de24
git-version-gen: convert leading TABs to spaces
Jim Meyering <meyering@redhat.com>
parents:
14094
diff
changeset
|
176 # Recreate the number of commits and rewrite such that the |
a6c3d8a0de24
git-version-gen: convert leading TABs to spaces
Jim Meyering <meyering@redhat.com>
parents:
14094
diff
changeset
|
177 # result is the same as if we were using the newer version |
a6c3d8a0de24
git-version-gen: convert leading TABs to spaces
Jim Meyering <meyering@redhat.com>
parents:
14094
diff
changeset
|
178 # of git describe. |
a6c3d8a0de24
git-version-gen: convert leading TABs to spaces
Jim Meyering <meyering@redhat.com>
parents:
14094
diff
changeset
|
179 vtag=`echo "$v" | sed 's/-.*//'` |
a6c3d8a0de24
git-version-gen: convert leading TABs to spaces
Jim Meyering <meyering@redhat.com>
parents:
14094
diff
changeset
|
180 commit_list=`git rev-list "$vtag"..HEAD 2>/dev/null` \ |
a6c3d8a0de24
git-version-gen: convert leading TABs to spaces
Jim Meyering <meyering@redhat.com>
parents:
14094
diff
changeset
|
181 || { commit_list=failed; |
a6c3d8a0de24
git-version-gen: convert leading TABs to spaces
Jim Meyering <meyering@redhat.com>
parents:
14094
diff
changeset
|
182 echo "$0: WARNING: git rev-list failed" 1>&2; } |
a6c3d8a0de24
git-version-gen: convert leading TABs to spaces
Jim Meyering <meyering@redhat.com>
parents:
14094
diff
changeset
|
183 numcommits=`echo "$commit_list" | wc -l` |
a6c3d8a0de24
git-version-gen: convert leading TABs to spaces
Jim Meyering <meyering@redhat.com>
parents:
14094
diff
changeset
|
184 v=`echo "$v" | sed "s/\(.*\)-\(.*\)/\1-$numcommits-\2/"`; |
a6c3d8a0de24
git-version-gen: convert leading TABs to spaces
Jim Meyering <meyering@redhat.com>
parents:
14094
diff
changeset
|
185 test "$commit_list" = failed && v=UNKNOWN |
a6c3d8a0de24
git-version-gen: convert leading TABs to spaces
Jim Meyering <meyering@redhat.com>
parents:
14094
diff
changeset
|
186 ;; |
9719
ec87f62b97b8
Enable use of older two part flavor 'git describe'.
Bob Proulx <bob@proulx.com>
parents:
9677
diff
changeset
|
187 esac |
ec87f62b97b8
Enable use of older two part flavor 'git describe'.
Bob Proulx <bob@proulx.com>
parents:
9677
diff
changeset
|
188 |
19039
bb20c8393f79
git-version-gen: another fix for tags with "-"
Paul Eggert <eggert@cs.ucla.edu>
parents:
19037
diff
changeset
|
189 # Change the penultimate "-" to ".", for version-comparing tools. |
bb20c8393f79
git-version-gen: another fix for tags with "-"
Paul Eggert <eggert@cs.ucla.edu>
parents:
19037
diff
changeset
|
190 # Remove the "g" to save a byte. |
bb20c8393f79
git-version-gen: another fix for tags with "-"
Paul Eggert <eggert@cs.ucla.edu>
parents:
19037
diff
changeset
|
191 v=`echo "$v" | sed 's/-\([^-]*\)-g\([^-]*\)$/.\1-\2/'`; |
14372
b894b1646164
git-version-gen: skip "-dirty" check when appropriate
Jim Meyering <meyering@redhat.com>
parents:
14133
diff
changeset
|
192 v_from_git=1 |
17246
7d2aa4fc02ab
git-version-gen: avoid test -z portability glitch
Eric Blake <eblake@redhat.com>
parents:
17245
diff
changeset
|
193 elif test "x$fallback" = x || git --version >/dev/null 2>&1; then |
17960
1c04e5182252
git-version-gen: revert "detect untagged revisions"
Mats Erik Andersson <mats.andersson@gisladisker.se>
parents:
17958
diff
changeset
|
194 v=UNKNOWN |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
195 else |
17245
179b150e5256
git-version-gen: add --fallback option to use if git is not present
Peter Rosin <peda@lysator.liu.se>
parents:
16706
diff
changeset
|
196 v=$fallback |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
197 fi |
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
198 |
17960
1c04e5182252
git-version-gen: revert "detect untagged revisions"
Mats Erik Andersson <mats.andersson@gisladisker.se>
parents:
17958
diff
changeset
|
199 v=`echo "$v" |sed "s/^$prefix//"` |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
200 |
14372
b894b1646164
git-version-gen: skip "-dirty" check when appropriate
Jim Meyering <meyering@redhat.com>
parents:
14133
diff
changeset
|
201 # Test whether to append the "-dirty" suffix only if the version |
b894b1646164
git-version-gen: skip "-dirty" check when appropriate
Jim Meyering <meyering@redhat.com>
parents:
14133
diff
changeset
|
202 # string we're using came from git. I.e., skip the test if it's "UNKNOWN" |
b894b1646164
git-version-gen: skip "-dirty" check when appropriate
Jim Meyering <meyering@redhat.com>
parents:
14133
diff
changeset
|
203 # or if it came from .tarball-version. |
17246
7d2aa4fc02ab
git-version-gen: avoid test -z portability glitch
Eric Blake <eblake@redhat.com>
parents:
17245
diff
changeset
|
204 if test "x$v_from_git" != x; then |
18663
caf9d6314c8f
maint: time stamp -> timestamp
Paul Eggert <eggert@cs.ucla.edu>
parents:
18626
diff
changeset
|
205 # Don't declare a version "dirty" merely because a timestamp has changed. |
14372
b894b1646164
git-version-gen: skip "-dirty" check when appropriate
Jim Meyering <meyering@redhat.com>
parents:
14133
diff
changeset
|
206 git update-index --refresh > /dev/null 2>&1 |
9452
595a77da32de
git-version-gen: sync from coreutils.
Jim Meyering <meyering@redhat.com>
parents:
9175
diff
changeset
|
207 |
14372
b894b1646164
git-version-gen: skip "-dirty" check when appropriate
Jim Meyering <meyering@redhat.com>
parents:
14133
diff
changeset
|
208 dirty=`exec 2>/dev/null;git diff-index --name-only HEAD` || dirty= |
b894b1646164
git-version-gen: skip "-dirty" check when appropriate
Jim Meyering <meyering@redhat.com>
parents:
14133
diff
changeset
|
209 case "$dirty" in |
b894b1646164
git-version-gen: skip "-dirty" check when appropriate
Jim Meyering <meyering@redhat.com>
parents:
14133
diff
changeset
|
210 '') ;; |
b894b1646164
git-version-gen: skip "-dirty" check when appropriate
Jim Meyering <meyering@redhat.com>
parents:
14133
diff
changeset
|
211 *) # Append the suffix only if there isn't one already. |
b894b1646164
git-version-gen: skip "-dirty" check when appropriate
Jim Meyering <meyering@redhat.com>
parents:
14133
diff
changeset
|
212 case $v in |
b894b1646164
git-version-gen: skip "-dirty" check when appropriate
Jim Meyering <meyering@redhat.com>
parents:
14133
diff
changeset
|
213 *-dirty) ;; |
b894b1646164
git-version-gen: skip "-dirty" check when appropriate
Jim Meyering <meyering@redhat.com>
parents:
14133
diff
changeset
|
214 *) v="$v-dirty" ;; |
b894b1646164
git-version-gen: skip "-dirty" check when appropriate
Jim Meyering <meyering@redhat.com>
parents:
14133
diff
changeset
|
215 esac ;; |
b894b1646164
git-version-gen: skip "-dirty" check when appropriate
Jim Meyering <meyering@redhat.com>
parents:
14133
diff
changeset
|
216 esac |
b894b1646164
git-version-gen: skip "-dirty" check when appropriate
Jim Meyering <meyering@redhat.com>
parents:
14133
diff
changeset
|
217 fi |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
218 |
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
219 # Omit the trailing newline, so that m4_esyscmd can use the result directly. |
17813
11bf208f2615
git-version-gen: do not print new line characters
KO Myung-Hun <komh78@gmail.com>
parents:
17711
diff
changeset
|
220 printf %s "$v" |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
221 |
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
222 # Local variables: |
19553
f5dae61a17f4
maint: write-file-hooks -> before-save-hook
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
223 # eval: (add-hook 'before-save-hook 'time-stamp) |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
224 # time-stamp-start: "scriptversion=" |
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
225 # time-stamp-format: "%:y-%02m-%02d.%02H" |
18195
6ee445128d2a
Port Universal Time settings to strict POSIX
Paul Eggert <eggert@cs.ucla.edu>
parents:
18189
diff
changeset
|
226 # time-stamp-time-zone: "UTC0" |
12902
74f6f4021fe0
bootstrap, git-version-gen: use timestamp
Eric Blake <eblake@redhat.com>
parents:
12825
diff
changeset
|
227 # time-stamp-end: "; # UTC" |
9175
c7f825e034ad
* build-aux/git-version-gen: New file, from coreutils. For details, see
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
228 # End: |