Does Git have the feature that Subversion had keyword substitution or something?

Asked

Viewed 38 times

0

When I worked with cvs and Subversion I remember a resource where we put some notes in the archives and each time we did one commit these data were updated. In general the data referred to the date, author and number of the commit. It was something like the example below

/*
 *   $Author: joazinho $
 *   $Rev: 153 $
 *   $LastChangedDate: 2016-04-15 17:32:15 -0300 (Fri, 15 Apr 2016) $
 */

In Git something similar for me to get the branch / tag, hash, etc... that is native.

1 answer

2


Directly has no no. But it is possible to do scripts to do it for you.

It makes available attributes which can be used in your script.

Example:

MYVERSION = '1.090'
## Call script to do updateVersion from .git/hooks/pre-commit
def updateVersion
  # We add 1 because the next commit is probably one more - though this is a race
  commits = %x[git log #{$0} | grep '^commit ' | wc -l].to_i + 1
  vers = "1.%0.3d" % commits

  t = File.read($0)
  t.gsub!(/^MYVERSION = '(.*)'$/, "MYVERSION = '#{vers}'")
  bak = $0+'.bak'
  File.open(bak,'w') { |f| f.puts t }
  perm = File.stat($0).mode & 0xfff
  File.rename(bak,$0)
  File.chmod(perm,$0)
  exit
end

Source.

More examples.

The Whole notion of keyword substitution is just Totally idiotic. It’s trivial to do "Outside" of the current content tracking, if you want to have it when Doing release Trees as tar-Balls etc.

-- Linus Tovards

Browser other questions tagged

You are not signed in. Login or sign up in order to post.