Giter Club home page Giter Club logo

gitversioner's Introduction

Git Versioner

Git Versioner takes a version string (e.g. from git describe) and splits it up into separate components.

The resulting Version object can then easily be printed according to Semantic Versioning rules.

It also provides a command line option to print the result as C preprocessor macros, so that it can easily be included in a build script.

You can pass any version string to GitVersioner, it does not need to come from git describe directly. The following and more are supported:

  • Git tags:
    • Plain: v1.2.3
    • Pre-Releases: v1.2.3-beta6
    • Dirty workspace: v1.2-dirty
    • Git describe output: v1.2-50-gf00000d
  • Version number without leading 'v':
    • 1.2
    • 1.2-beta6

Overview

The resulting semantic version always follows this pattern:

  • Major.Minor.Patch (if one of them is not found in the tag or no tag is present at all, 0 will be used)
  • Any pre-release identifiers (separated from the version number by a '-')
  • Build metadata (commit count since last tag, commit hash, etc.), separated from previous string by '+'

That means, the Major, Minor, and Patch parts will always be a pure numerical representation. Any additional information will be put in the Semantic Versioning string.

Usage

./GitVersioner.py -h
usage: GitVersioner.py [-h] [-f FILE | -g [GIT_DIR]] [-d DIRTY_SUFFIX] [-m]
                       [-p PREFIX]
                       [version_string]

Splits a version string into individual components.

positional arguments:
  version_string        Version string to parse. If omitted, the version will
                        be read from stdin. Will be ignored if either -f or -g
                        are given.

optional arguments:
  -h, --help            show this help message and exit
  -f FILE, --file FILE  Read version string from file. Only interprets the
                        first line of the given file.
  -g [GIT_DIR], --git-dir [GIT_DIR]
                        Invoke `git describe` on optional directory. Default:
                        current working directory
  -d DIRTY_SUFFIX, --dirty-suffix DIRTY_SUFFIX
                        Suffix to use when the build version is dirty.
                        Default: 'dirty'

Macros:
  C preprocessor options

  -m, --macros          Output C preprocessor style macros
  -p PREFIX, --prefix PREFIX
                        Prefix to add before each preprocessor variable

Example

Simple version

GitVersioner.py v1.1

Major: 1
Minor: 1
Patch: 0
SemVer: 1.1.0

Pre-Releases

GitVersioner.py v1.1-alpha.3

Major: 1
Minor: 1
Patch: 0
SemVer: 1.1.0-alpha.3

Support for git describe features

GitVersioner.py v1.1.0-23-gf096607-dirty

Major: 1
Minor: 1
Patch: 0
SemVer: 1.1.0+23.f096607.dirty

Preprocessor output with custom prefix

GitVersioner.py v1.1.0-23-gf096607-dirty --macros --prefix "WOW_"

#define WOW_MAJOR 1
#define WOW_MINOR 1
#define WOW_PATCH 0
#define WOW_SEM_VER "1.1.0+23.f096607.dirty"

gitversioner's People

Contributors

nioncode avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.