Coverage for python/lsst/sconsUtils/vcs/git.py: 78%
14 statements
« prev ^ index » next coverage.py v7.17.5, created at 2026-11-26 19:18 +0000
« prev ^ index » next coverage.py v7.17.5, created at 2026-11-26 19:18 +0000
1# This file is part of sconsUtils.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <https://www.gnu.org/licenses/>.
22"""A simple python interface to git, using `os.popen`.
24Based on the svn interface.
26If ever we want to do anything clever, we should use one of
27the supported python packages
28"""
30import os
32from .. import state, utils
35def guessVersionName():
36 """Guess a version name.
38 Returns
39 -------
40 name : `str`
41 Descriptive name of the repository version state.
42 """
43 name = "unknown"
45 if not os.path.exists(".git"): 45 ↛ 48line 45 didn't jump to line 48 because the condition on line 45 was always true
46 state.log.warn(f"Cannot guess version without .git directory; will be set to '{name}'.")
47 else:
48 name = utils.runExternal("git describe --always --dirty --tags", fatal=False).strip()
50 return name
53def guessFingerprint():
54 """Guess a unique fingerprint.
56 Returns
57 -------
58 fingerprint : `str`
59 SHA1 of current repository state.
60 """
61 fingerprint = "0x0"
63 if not os.path.exists(".git"): 63 ↛ 66line 63 didn't jump to line 66 because the condition on line 63 was always true
64 state.log.warn(f"Cannot guess fingerprint without .git directory; will be set to '{fingerprint}'.")
65 else:
66 fingerprint = utils.runExternal(
67 "git describe --match= --always --abbrev=0 --dirty", fatal=False
68 ).strip()
70 return fingerprint