1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 # If you change this file, you'll probably also want to make the same
6 # changes in apps/workbench/lib/app_version.rb.
9 def self.git(*args, &block)
10 IO.popen(["git", "--git-dir", ".git"] + args, "r",
11 chdir: Rails.root.join('../..'),
20 # Return abbrev commit hash for current code version: "abc1234", or
21 # "abc1234-modified" if there are uncommitted changes. If present,
22 # return contents of {root}/git-commit.version instead.
24 if (cached = Rails.configuration.source_version || @hash)
28 # Read the version from our package's git-commit.version file, if available.
30 @hash = IO.read(Rails.root.join("git-commit.version")).strip
34 if @hash.nil? or @hash.empty?
36 local_modified = false
37 git("status", "--porcelain") do |git_pipe|
38 git_pipe.each_line do |_|
40 # Continue reading the pipe so git doesn't get SIGPIPE.
44 git("log", "-n1", "--format=%H") do |git_pipe|
45 git_pipe.each_line do |line|
46 @hash = line.chomp[0...8] + (local_modified ? '-modified' : '')
50 rescue SystemCallError