Coverage for src/susi/utils/git.py: 88%

16 statements  

« prev     ^ index     » next       coverage.py v7.5.0, created at 2025-06-13 14:15 +0000

1#!/usr/bin/env python3 

2# -*- coding: utf-8 -*- 

3""" 

4Utility for interaction with the surrounding git repository 

5 

6@author: hoelken 

7""" 

8 

9import git 

10import os 

11 

12 

13class Git: 

14 """ 

15 Git repository interaction class 

16 """ 

17 

18 @staticmethod 

19 def folder(): 

20 return os.path.dirname(os.path.realpath(__file__)) 

21 

22 @staticmethod 

23 def current_sha(): 

24 """ 

25 Get the `sha` of the current git commit we are working on 

26 """ 

27 return git.Repo(Git.folder(), search_parent_directories=True).head.object.hexsha 

28 

29 @staticmethod 

30 def current_branch(): 

31 """ 

32 Get the branch name of the currently checked out git branch 

33 """ 

34 return git.Repo(Git.folder(), search_parent_directories=True).active_branch 

35 

36 @staticmethod 

37 def version() -> str: 

38 """ 

39 Get version as 'current_sha (current_branch)' 

40 """ 

41 return '{} ({})'.format(Git.current_sha(), Git.current_branch())