@@ -47,21 +47,15 @@ def _version_from_git_tree(base_version: str) -> str | None:
47
47
try :
48
48
root_directory = os .path .dirname (os .path .realpath (__file__ ))
49
49
50
- # Get date string from date of most recent git commit.
51
- p = subprocess .Popen (["git" , "show" , "-s" , "--format=%at" , "HEAD" ],
50
+ # Get date string from date of most recent git commit, and the abbreviated
51
+ # hash of that commit.
52
+ p = subprocess .Popen (["git" , "show" , "-s" , "--format=%at-%h" , "HEAD" ],
52
53
cwd = root_directory ,
53
54
stdout = subprocess .PIPE , stderr = subprocess .PIPE )
54
55
stdout , _ = p .communicate ()
55
- timestamp = int ( stdout .decode ().strip ())
56
- datestring = datetime .date .fromtimestamp (timestamp ).strftime ("%Y%m%d" )
56
+ timestamp , commit_hash = stdout .decode ().strip (). split ( '-' , 1 )
57
+ datestring = datetime .date .fromtimestamp (int ( timestamp ) ).strftime ("%Y%m%d" )
57
58
assert datestring .isnumeric ()
58
-
59
- # Get commit hash from most recent git commit.
60
- p = subprocess .Popen (["git" , "describe" , "--long" , "--always" ],
61
- cwd = root_directory ,
62
- stdout = subprocess .PIPE , stderr = subprocess .PIPE )
63
- stdout , _ = p .communicate ()
64
- commit_hash = stdout .decode ().strip ().rsplit ('-g' , 1 )[- 1 ]
65
59
assert commit_hash .isalnum ()
66
60
except :
67
61
return None
0 commit comments