Blame get-version

Packit e9ba0d
#!/bin/sh
Packit e9ba0d
#
Packit e9ba0d
# get-version
Packit e9ba0d
#
Packit e9ba0d
# Copyright © 2009 Guillem Jover <guillem@hadrons.org>
Packit e9ba0d
#
Packit e9ba0d
# Redistribution and use in source and binary forms, with or without
Packit e9ba0d
# modification, are permitted provided that the following conditions
Packit e9ba0d
# are met:
Packit e9ba0d
# 1. Redistributions of source code must retain the above copyright
Packit e9ba0d
#    notice, this list of conditions and the following disclaimer.
Packit e9ba0d
# 2. Redistributions in binary form must reproduce the above copyright
Packit e9ba0d
#    notice, this list of conditions and the following disclaimer in the
Packit e9ba0d
#    documentation and/or other materials provided with the distribution.
Packit e9ba0d
# 3. The name of the author may not be used to endorse or promote products
Packit e9ba0d
#    derived from this software without specific prior written permission.
Packit e9ba0d
#
Packit e9ba0d
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
Packit e9ba0d
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
Packit e9ba0d
# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
Packit e9ba0d
# THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
Packit e9ba0d
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
Packit e9ba0d
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
Packit e9ba0d
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
Packit e9ba0d
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
Packit e9ba0d
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
Packit e9ba0d
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit e9ba0d
Packit e9ba0d
if [ -f .dist-version ]; then
Packit e9ba0d
  # Get the version from the file distributed in the tarball.
Packit e9ba0d
  version=$(cat .dist-version)
Packit e9ba0d
elif [ -e .git ]; then
Packit e9ba0d
  # Ger the version from the git repository.
Packit e9ba0d
  version=$(git describe --tags --always --match [0-9]* 2> /dev/null)
Packit e9ba0d
Packit e9ba0d
  # Check if we are on a dirty checkout.
Packit e9ba0d
  git update-index --refresh -q >/dev/null
Packit e9ba0d
  dirty=$(git diff-index --name-only --ignore-submodules=untracked HEAD 2>/dev/null)
Packit e9ba0d
  if [ -n "$dirty" ]; then
Packit e9ba0d
    version="$version-dirty"
Packit e9ba0d
  fi
Packit e9ba0d
else
Packit e9ba0d
  version=$(date +%F)
Packit e9ba0d
fi
Packit e9ba0d
Packit e9ba0d
# Use printf to avoid the trailing new line that m4_esyscmd would not handle.
Packit e9ba0d
printf "$version"