Skip to content

Commit 8ea43c8

Browse files
authored
Merge pull request #84 from smkent/skip-empty-updates
Skip cruft updates without template modifications
2 parents 1b2d5ae + 0199bed commit 8ea43c8

2 files changed

Lines changed: 34 additions & 11 deletions

File tree

cookie_python/manage/repo.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ def run(
9595
kwargs.setdefault("cwd", self.clone_path)
9696
return subprocess.run(*popenargs, check=check, **kwargs)
9797

98+
def reset(self) -> None:
99+
self.run(["git", "checkout", "--", "."], check=True)
100+
98101
def shell(self) -> None:
99102
if sys.__stdin__.isatty():
100103
self.logger.info('Starting shell. Run "exit 1" to abort.')

cookie_python/manage/update.py

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
import os
2+
from functools import wraps
23
from pathlib import Path
3-
from typing import Optional
4+
from typing import Any, Callable, Optional
45

56
from .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
823
def 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
7696
def update_dependencies(repo: RepoSandbox) -> Optional[str]:
7797
repo.run(["poetry", "run", "pre-commit", "autoupdate"])
7898
updates = repo.run(

0 commit comments

Comments
 (0)