LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
git.py
Go to the documentation of this file.
1 #
2 # A simple python interface to git, using os.popen
3 # Based on the svn interface.
4 #
5 # If ever we want to do anything clever, we should use one of
6 # the supported python packages
7 #
8 from __future__ import absolute_import, division, print_function
9 import os
10 import re
11 from .. import state
12 from .. import utils
13 
15  """Guess a version name"""
16 
17  if not os.path.exists(".git"):
18  state.log.warn("Cannot guess version without .git directory; version will be set to 'unknown'.")
19  return "unknown"
20  status = utils.runExternal("git status --porcelain --untracked-files=no", fatal=True)
21  if status.strip():
22  raise RuntimeError("Error with git version: uncommitted changes")
23  desc = utils.runExternal("git describe --tags --always", fatal=True)
24  return desc.strip()
25 
27  """Return (fingerprint, modified) where fingerprint is the repository's SHA1"""
28  fingerprint, modified = "0x0", False
29 
30  if not os.path.exists(".git"):
31  state.log.warn("Cannot guess fingerprint without .git directory; will be set to '%s'."
32  % fingerprint)
33  else:
34  status = utils.runExternal("git status --porcelain --untracked-files=no", fatal=True)
35  if status.strip():
36  modified = True
37  output = utils.runExternal("git rev-parse HEAD", fatal=False)
38 
39  fingerprint = output.strip()
40 
41  return fingerprint, modified