Can GIT do injection/token replacement at the point of code checkin?
PVCS did something for firm XYZ by injecting/token replacement for values. Case in point:
If we have code that looked like this:
/* $Workfile:$
* Created By: [Developer Name HERE]
* Created On: [Date created in mm/dd/ccyy format, HERE]
*
* Last Revision:
* $Revision:$
* $Date:$
* $Author:$
*
* All rights reserved.
*
*/
[INSERT MY AMAZING CODE HERE]
/*
$Log:$
*/
PVCS would turn it into the following, Yellow highlights would be updates to the file and Green highlights are my comments.
/* $Workfile: Constants.java $ (Filename injected)
* Created By: [Developer Name HERE]
* Created On: [Date created in mm/dd/ccyy format, HERE]
*
* Last Revision:
* $Revision: 1.0 $
* $Date: Jun 26 2015 06:50:52 $
* $Author: Jsmith $
*
* All rights reserved.
*
*/
/*
$Log: M:/PVCS/xxx Project Database/archives/xx/EJB/src/com/xxxxcommon/Constants.java-arc $
// Rev 1.0 Aug 14 2009 18:10:30 jsmith
// Initial revision. (Comment I used at point of code check-in)
*/
Can we do that if so what do we need to change to make sure we can do it consistently across all of the source code base?
git
does support some limited variable expansion functions, although they are not done at check-in time. Ingit help gitattributes
, see the sections onident
andexport-subst
, as well as thefilter
options mentioned in VonC's answer. Theident
expansion occurs on checkout, while theexport-subst
only occurs when usinggit archive
. Thefilter
option applies to both checkin and checkout paths, and can be much more general, but useful configuration of it takes a fair amount of work for anything that has different requirements for different sorts of files (e.g. C code vs shell scripts - different comment formats) or other complex requirements.