LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
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