From: Matt Haley Date: 2009-10-01T02:29:31+09:00 Subject: Re: Get current working copy version in subversion/git On Thu, 1 Oct 2009, Anthony Metcalf wrote: > Hi, > > How would I report the current revision, of the subversion/git repo > that is holding a ruby app? I use this in a Rails initializer, it works under Windows as well. # # # Call +git+ and obtain the current commit SHA1 and commit date. Store these values # in +APP_VERSION_COMMIT_ID+ and +APP_VERSION_COMMIT_DATE+. Then define # +APP_VERSION+ to be a string of the two. git_cmd = 'git show --pretty=format:"%H|%ci" --quiet' commit_id = nil commit_date = nil begin unless RAILS_ENV=='test' commit_id, commit_date = IO.popen(git_cmd) {|f| log_entry = f.gets log_entry.split("|") unless log_entry.nil? } else commit_id, commit_date = '','' end rescue Errno::ENOENT # git not installed commit_id = 'Unknown' commit_date = '' end unless defined?(::APP_VERSION) APP_VERSION_COMMIT_ID = commit_id APP_VERSION_COMMIT_DATE = commit_date APP_VERSION = "#{commit_id} #{commit_date}" end