@@ -34,44 +34,33 @@ def from_config(cls, config: dict[str, Any]) -> RevInfo:
34
34
return cls (config ['repo' ], config ['rev' ], None )
35
35
36
36
def update (self , tags_only : bool , freeze : bool ) -> RevInfo :
37
- git_cmd = ('git' , * git .NO_FS_MONITOR )
37
+ with tempfile .TemporaryDirectory () as tmp :
38
+ _git = ('git' , * git .NO_FS_MONITOR , '-C' , tmp )
38
39
39
- if tags_only :
40
- tag_cmd = (
41
- * git_cmd , 'describe' ,
42
- 'FETCH_HEAD' , '--tags' , '--abbrev=0' ,
43
- )
44
- else :
45
- tag_cmd = (
46
- * git_cmd , 'describe' ,
47
- 'FETCH_HEAD' , '--tags' , '--exact' ,
48
- )
40
+ if tags_only :
41
+ tag_opt = '--abbrev=0'
42
+ else :
43
+ tag_opt = '--exact'
44
+ tag_cmd = (* _git , 'describe' , 'FETCH_HEAD' , '--tags' , tag_opt )
49
45
50
- with tempfile .TemporaryDirectory () as tmp :
51
46
git .init_repo (tmp , self .repo )
47
+ cmd_output_b (* _git , 'config' , 'extensions.partialClone' , 'true' )
52
48
cmd_output_b (
53
- * git_cmd , 'config' , 'extensions.partialClone' , 'true' ,
54
- cwd = tmp ,
55
- )
56
- cmd_output_b (
57
- * git_cmd , 'fetch' , 'origin' , 'HEAD' ,
49
+ * _git , 'fetch' , 'origin' , 'HEAD' ,
58
50
'--quiet' , '--filter=blob:none' , '--tags' ,
59
- cwd = tmp ,
60
51
)
61
52
62
53
try :
63
- rev = cmd_output (* tag_cmd , cwd = tmp )[1 ].strip ()
54
+ rev = cmd_output (* tag_cmd )[1 ].strip ()
64
55
except CalledProcessError :
65
- cmd = (* git_cmd , 'rev-parse' , 'FETCH_HEAD' )
66
- rev = cmd_output (* cmd , cwd = tmp )[1 ].strip ()
56
+ rev = cmd_output (* _git , 'rev-parse' , 'FETCH_HEAD' )[1 ].strip ()
67
57
else :
68
58
if tags_only :
69
59
rev = git .get_best_candidate_tag (rev , tmp )
70
60
71
61
frozen = None
72
62
if freeze :
73
- exact_rev_cmd = (* git_cmd , 'rev-parse' , rev )
74
- exact = cmd_output (* exact_rev_cmd , cwd = tmp )[1 ].strip ()
63
+ exact = cmd_output (* _git , 'rev-parse' , rev )[1 ].strip ()
75
64
if exact != rev :
76
65
rev , frozen = exact , rev
77
66
return self ._replace (rev = rev , frozen = frozen )
0 commit comments