1 # If you change this file, you'll probably also want to make the same
2 # changes in apps/workbench/lib/app_version.rb.
5 def self.git(*args, &block)
6 IO.popen(["git", "--git-dir", ".git"] + args, "r",
7 chdir: Rails.root.join('../..'),
16 # Return abbrev commit hash for current code version: "abc1234", or
17 # "abc1234-modified" if there are uncommitted changes. If present,
18 # return contents of {root}/git-commit.version instead.
20 if (cached = Rails.configuration.source_version || @hash)
24 # Read the version from our package's git-commit.version file, if available.
26 @hash = IO.read(Rails.root.join("git-commit.version")).strip
30 if @hash.nil? or @hash.empty?
32 local_modified = false
33 git("status", "--porcelain") do |git_pipe|
34 git_pipe.each_line do |_|
36 # Continue reading the pipe so git doesn't get SIGPIPE.
40 git("log", "-n1", "--format=%H") do |git_pipe|
41 git_pipe.each_line do |line|
42 @hash = line.chomp[0...8] + (local_modified ? '-modified' : '')
46 rescue SystemCallError