11import os
2+ from functools import wraps
23from pathlib import Path
3- from typing import Optional
4+ from typing import Any , Callable , Optional
45
56from .repo import RepoSandbox
67
78
9+ def repo_reset (
10+ f : Callable [[RepoSandbox ], Optional [Any ]]
11+ ) -> Callable [..., Any ]:
12+ @wraps (f )
13+ def _inner (repo : RepoSandbox ) -> Optional [Any ]:
14+ result = f (repo )
15+ if result is None :
16+ repo .reset ()
17+ return result
18+
19+ return _inner
20+
21+
22+ @repo_reset
823def update_cruft (repo : RepoSandbox ) -> Optional [str ]:
924 before_ref = repo .cruft_attr ("commit" )
1025 repo .run (["poetry" , "env" , "remove" , "--all" ], check = False )
@@ -14,6 +29,19 @@ def update_cruft(repo: RepoSandbox) -> Optional[str]:
1429 after_ref = repo .cruft_attr ("commit" )
1530 if before_ref == after_ref :
1631 return None
32+ git_status = (
33+ repo .run (
34+ ["git" , "status" , "--porcelain" , "--" , ":!.cruft.json" ],
35+ capture_output = True ,
36+ check = True ,
37+ )
38+ .stdout .decode ()
39+ .strip ()
40+ .splitlines ()
41+ )
42+ if not git_status :
43+ # Skip updates with no template changes
44+ return None
1745 for try_count in range (1 ):
1846 rej_files = [
1947 fn .strip ()
@@ -25,16 +53,7 @@ def update_cruft(repo: RepoSandbox) -> Optional[str]:
2553 .stdout .decode ()
2654 .splitlines ()
2755 ]
28- conflicts = any (
29- line .startswith ("U" )
30- for line in repo .run (
31- ["git" , "status" , "--porcelain" ],
32- capture_output = True ,
33- check = True ,
34- )
35- .stdout .decode ()
36- .splitlines ()
37- )
56+ conflicts = any (line .startswith ("U" ) for line in git_status )
3857 if rej_files or conflicts :
3958 if try_count == 0 :
4059 repo .logger .error (f"Conflicts found: { rej_files } " )
@@ -73,6 +92,7 @@ def update_cruft(repo: RepoSandbox) -> Optional[str]:
7392 )
7493
7594
95+ @repo_reset
7696def update_dependencies (repo : RepoSandbox ) -> Optional [str ]:
7797 repo .run (["poetry" , "run" , "pre-commit" , "autoupdate" ])
7898 updates = repo .run (
0 commit comments