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

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

2 

3Based on the svn interface. 

4 

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 

11 

12 

13def guessVersionName(): 

14 """Guess a version name 

15 

16 Returns 

17 ------- 

18 name : `str` 

19 Descriptive name of the repository version state. 

20 """ 

21 

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

30 

31 

32def guessFingerprint(): 

33 """Guess a unique fingerprint. 

34 

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 

43 

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) 

52 

53 fingerprint = output.strip() 

54 

55 return fingerprint, modified