@@ -23,17 +23,47 @@ def add_prefix_to_path(src_list, path, check_files=True):
2323 raise RuntimeError (f"Path '{ path } ' does not exist" )
2424 return paths
2525
26- def exec_cmd (cmd ):
27- r = subprocess .run (cmd , capture_output = True , text = True )
28- return r .stdout .strip ()
26+ def exec_cmd (cmd , cwd = None ):
27+ r = subprocess .run (cmd , capture_output = True , text = True , cwd = cwd )
28+ return r .returncode , r . stdout .strip ()
2929
3030def get_git_info ():
31- d = {}
32- d ["branch" ] = exec_cmd (["git" , "rev-parse" , "--abbrev-ref" , "HEAD" ])
33- d ["tag" ] = exec_cmd ([ "git" , "describe" , "--exact-match" , "--tags" ])
34- d ["diff" ] = exec_cmd ([ "git" , "diff" , "--quiet" , "--exit-code" ])
35- d ["rev" ] = exec_cmd (["git" , "log" , "--pretty=format:%h" , "-n" , "1" ])
36- d ["root" ] = exec_cmd (["git" , "rev-parse" , "--show-toplevel" ])
31+ d = {
32+ "branch" : "None" ,
33+ "tag" : "" ,
34+ "diff" : "" ,
35+ "rev" : "" ,
36+ "root" : repo_root ,
37+ }
38+
39+ rc , _ = exec_cmd (["git" , "rev-parse" , "--is-inside-work-tree" ], cwd = repo_root )
40+ if rc != 0 :
41+ return d
42+
43+ rc , root = exec_cmd (["git" , "rev-parse" , "--show-toplevel" ], cwd = repo_root )
44+ if rc == 0 and root :
45+ d ["root" ] = root
46+
47+ rc , branch = exec_cmd (["git" , "symbolic-ref" , "--short" , "-q" , "HEAD" ], cwd = repo_root )
48+ if rc == 0 and branch :
49+ d ["branch" ] = branch
50+ else :
51+ d ["branch" ] = "detached"
52+
53+ rc , rev = exec_cmd (["git" , "describe" , "--tags" , "--long" , "--always" , "--abbrev=7" ], cwd = repo_root )
54+ if rc == 0 :
55+ d ["rev" ] = rev
56+
57+ rc , tag = exec_cmd (["git" , "describe" , "--exact-match" , "--tags" , "HEAD" ], cwd = repo_root )
58+ if rc == 0 and tag :
59+ d ["tag" ] = tag
60+
61+ rc , status = exec_cmd (["git" , "status" , "--porcelain" , "--untracked-files=normal" ], cwd = repo_root )
62+ if rc == 0 and status :
63+ d ["diff" ] = "+"
64+ if d ["tag" ]:
65+ d ["tag" ] = d ["tag" ] + "+"
66+
3767 return d
3868
3969def configure_file (file , replacements ):
0 commit comments