1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
6 def self.git(*args, &block)
7 IO.popen(["git", "--git-dir", ".git"] + args, "r",
8 chdir: Rails.root.join('../..'),
15 @package_version = nil
18 # Return abbrev commit hash for current code version: "abc1234", or
19 # "abc1234-modified" if there are uncommitted changes. If present,
20 # return contents of {root}/git-commit.version instead.
22 if (cached = Rails.configuration.source_version || @hash)
26 # Read the version from our package's git-commit.version file, if available.
28 @hash = IO.read(Rails.root.join("git-commit.version")).strip
32 if @hash.nil? or @hash.empty?
34 local_modified = false
35 git("status", "--porcelain") do |git_pipe|
36 git_pipe.each_line do |_|
38 # Continue reading the pipe so git doesn't get SIGPIPE.
42 git("log", "-n1", "--format=%H") do |git_pipe|
43 git_pipe.each_line do |line|
44 @hash = line.chomp[0...8] + (local_modified ? '-modified' : '')
48 rescue SystemCallError
55 def self.package_version
56 if (cached = Rails.configuration.package_version || @package_version)
61 @package_version = IO.read(Rails.root.join("package-build.version")).strip
63 @package_version = "unknown"