Skip to main content

No project description provided

Project description

Git Substitute

This repository contains a basic tool to generate files with Git information through templates. A typical application could be embedding Git version info in source code right before compilation

Installing

From a local clone, run poetry install or pip install . [-e].

You can also install directly from git with pip install https://github.com/RobertoRoos/git-substitute.

How to use

Commands

Run as either git_substitute ... or python -m git_substitute ....

Typical usage: git_substitute current_version_template.cs. This will copy the template file, substitute Git variables and commands and create a new file with a similar name, but without _template in the name.

See git_substitute --help for all options.

Templates

Use {{...}} in template file for placeholders. There are types of content: variables and direct Git function calls.

Variables are in uppercase with underscores, and start with GIT_. E.g.: {{GIT_TAG}}.

Instead of predefined variables you could use direct calls to Git. These are lowercase and start with git .... E.g. {{git refname --dirty}}.
Note that the interface through GitPython is used, instead of opening a shell directly.

Variables

In case you are not sure what information to embed, use GIT_DESCRIPTION_DIRTY as it is very concise and clear.

Placeholder Description Example
GIT_HASH Full hash of the last commit 4cc498b3c37375d8d9138fdab553ced012cafc7a
GIT_HASH_SHORT 8-char hash of the last commit 4cc498b3
GIT_DATE Datetime of the last commit 17-12-2024 12:47:10
GIT_NOW The current date and time, not a git command at all 19-12-2024 16:20:35
GIT_TAG Most relevant tag (result of git tag) v1.0.0
GIT_BRANCH Current branch name master
GIT_DESCRIPTION Most relevant tag + number of commits since then + last commit (result of git describe --tags --always) v0.0.1-1-g4cc498b
GIT_DESCRIPTION_DIRTY Same as GIT_DESCRIPTION, except it also adds the --dirty argument to mark if there were uncommitted changes v0.0.1-1-g4cc498b-dirty
GIT_DIRTY 1 if there are uncommited chances, otherwise 0 0

To use literal placeholder symbols in your template, escape them with a backslash: \{\{ and \}\}.

Example

// File: src/version_template.cpp

#include <string>

// Specificy the version for this library
const std::string version = "{{GIT_DESCRIPTION_DIRTY}}";

Then in your build script you may have a step like:

git_substitute src/version_template.cpp

Which will create src/version.cpp and can be compiled into your application.

How to develop

Install with development dependencies with poetry install --with dev.

Poetry Dynamic Versioning is used for automatic version detection.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

git_substitute-0.1.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

git_substitute-0.1.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file git_substitute-0.1.0.tar.gz.

File metadata

  • Download URL: git_substitute-0.1.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.7 Windows/10

File hashes

Hashes for git_substitute-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b5314b6879549a807c547c3ae6121ddab4631efb26aa3bb633192a451463788e
MD5 3347b92d4cf1abcc0c5e7387e647dbf8
BLAKE2b-256 e602f3806b6c3fe4fef6b95b3a6b15272c288928c5741008cef9b7f7b60b8239

See more details on using hashes here.

File details

Details for the file git_substitute-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: git_substitute-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.7 Windows/10

File hashes

Hashes for git_substitute-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4e19fc2cb54c5cae98a819c8d9142feff3bdc3555d6e0268c90d448b9cbbc298
MD5 8bc45d8291b1e54cf2de68b9ea45c71a
BLAKE2b-256 f6601000fe2edc041ace6ca14a183a845ddc17ea76a10c3bfd444c02993cc04b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page