Git Centralized Workflow Version Numbering

We use Git with a central server, and our code should include the version number in the file. The way this is currently being done is as follows:

  • New developer makes "git clone"
  • In his local copy, he edits .git / hooks / pre-commit to call version.sh

version.sh (which is included in the root of the project) takes the version number from "git describe" and saves it in a file.

While this works, I would like to make sure that the version number is updated, even if the developer forgot to edit his binding before committing.

Since the server does not have a working copy, just calling (pre | post) -receive hooks does not work there, so I wonder if there is a way to do this.

+3
source share
2 answers

How about hooks/updatein a central repo that rejects, it commits without changes in the version file (with the name VERSIONin the example below)?

#! /bin/bash

refname="$1"
oldrev="$2"
newrev="$3"

if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then
  echo "Usage: $0 <ref> <oldrev> <newrev>" >&2
  exit 1
fi

if [ "$refname" != "refs/heads/master" ]; then
  exit 0
fi

if diff -bq <(git show $oldrev:VERSION) \
            <(git show $newrev:VERSION) >/dev/null
then
  echo "$0: VERSION unchanged; rejecting update" >&2
  exit 1
fi
+4
source

The x264 project automatically generates a version number, assuming git commits to the history. It is ported from svn, where, for example, versions were called r678, but someone prepared a script to generate numbers from git.

http://git.videolan.org/?p=x264.git;a=blob;f=version.sh;hb=HEAD

+1
source

Source: https://habr.com/ru/post/1724823/


All Articles