Coverage for python/lsst/sconsUtils/vcs/git.py: 22%

14 statements  

« prev     ^ index     » next       coverage.py v7.17.5, created at 2026-11-26 06:33 +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/>. 

21 

22"""A simple python interface to git, using `os.popen`. 

23 

24Based on the svn interface. 

25 

26If ever we want to do anything clever, we should use one of 

27the supported python packages 

28""" 

29 

30import os 

31 

32from .. import state, utils 

33 

34 

35def guessVersionName(): 

36 """Guess a version name. 

37 

38 Returns 

39 ------- 

40 name : `str` 

41 Descriptive name of the repository version state. 

42 """ 

43 name = "unknown" 

44 

45 if not os.path.exists(".git"): 

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() 

49 

50 return name 

51 

52 

53def guessFingerprint(): 

54 """Guess a unique fingerprint. 

55 

56 Returns 

57 ------- 

58 fingerprint : `str` 

59 SHA1 of current repository state. 

60 """ 

61 fingerprint = "0x0" 

62 

63 if not os.path.exists(".git"): 

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() 

69 

70 return fingerprint