Coverage for python/lsst/sconsUtils/vcs/git.py: 17%
22 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-24 23:29 -0700
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-24 23:29 -0700
1"""A simple python interface to git, using `os.popen`.
3Based on the svn interface.
5If ever we want to do anything clever, we should use one of
6the supported python packages
7"""
8import os
9from .. import state
10from .. import utils
13def guessVersionName():
14 """Guess a version name
16 Returns
17 -------
18 name : `str`
19 Descriptive name of the repository version state.
20 """
22 if not os.path.exists(".git"):
23 state.log.warn("Cannot guess version without .git directory; version will be set to 'unknown'.")
24 return "unknown"
25 status = utils.runExternal("git status --porcelain --untracked-files=no", fatal=True)
26 if status.strip():
27 raise RuntimeError("Error with git version: uncommitted changes")
28 desc = utils.runExternal("git describe --tags --always", fatal=True)
29 return desc.strip()
32def guessFingerprint():
33 """Guess a unique fingerprint.
35 Returns
36 -------
37 fingerprint : `str`
38 SHA1 of current repository state.
39 modified : `bool`
40 Flag to indicate whether the repository is in a modified state.
41 """
42 fingerprint, modified = "0x0", False
44 if not os.path.exists(".git"):
45 state.log.warn("Cannot guess fingerprint without .git directory; will be set to '%s'."
46 % fingerprint)
47 else:
48 status = utils.runExternal("git status --porcelain --untracked-files=no", fatal=True)
49 if status.strip():
50 modified = True
51 output = utils.runExternal("git rev-parse HEAD", fatal=False)
53 fingerprint = output.strip()
55 return fingerprint, modified