|
12 | 12 | from dda.utils.git.remote import Remote |
13 | 13 |
|
14 | 14 | if TYPE_CHECKING: |
| 15 | + from collections.abc import Iterable |
| 16 | + |
15 | 17 | from dda.utils.fs import Path |
16 | 18 | from dda.utils.git.commit import Commit, CommitDetails |
17 | 19 |
|
@@ -124,13 +126,29 @@ def get_commit_details(self, sha1: str) -> CommitDetails: |
124 | 126 | parent_shas=list(parents_str.split()), |
125 | 127 | ) |
126 | 128 |
|
| 129 | + def add(self, paths: Iterable[Path]) -> None: |
| 130 | + """ |
| 131 | + Add the given paths to the index. |
| 132 | + Will fail if any path is not under cwd. |
| 133 | + """ |
| 134 | + self.run(["add", *[str(path) for path in paths]]) |
| 135 | + |
| 136 | + def commit(self, message: str, *, allow_empty: bool = False) -> None: |
| 137 | + """ |
| 138 | + Commit the changes in the index. |
| 139 | + """ |
| 140 | + args = ["commit", "-m", message] |
| 141 | + if allow_empty: |
| 142 | + args.append("--allow-empty") |
| 143 | + self.run(args) |
| 144 | + |
127 | 145 | def commit_file(self, path: Path, *, content: str, commit_message: str) -> None: |
128 | 146 | """ |
129 | 147 | Create and commit a single file with the given content. |
130 | 148 | """ |
131 | 149 | path.write_text(content) |
132 | | - self.run(["add", str(path)]) # Will fail if path is not under cwd |
133 | | - self.run(["commit", "-m", commit_message]) |
| 150 | + self.add((path,)) |
| 151 | + self.commit(commit_message) |
134 | 152 |
|
135 | 153 | def _capture_diff_lines(self, *args: str, **kwargs: Any) -> list[str]: |
136 | 154 | diff_args = [ |
|
0 commit comments