(testrepo: Repository)
| 163 | |
| 164 | |
| 165 | def test_checkout_aborted_from_callbacks(testrepo: Repository) -> None: |
| 166 | ref_i18n = testrepo.lookup_reference('refs/heads/i18n') |
| 167 | |
| 168 | def read_bye_txt() -> bytes: |
| 169 | blob = testrepo[testrepo.create_blob_fromworkdir('bye.txt')] |
| 170 | assert isinstance(blob, Blob) |
| 171 | return blob.data |
| 172 | |
| 173 | s = testrepo.status() |
| 174 | assert s == {'bye.txt': FileStatus.WT_NEW} |
| 175 | |
| 176 | class MyCheckoutCallbacks(pygit2.CheckoutCallbacks): |
| 177 | def __init__(self) -> None: |
| 178 | super().__init__() |
| 179 | self.invoked_times = 0 |
| 180 | |
| 181 | def checkout_notify( |
| 182 | self, |
| 183 | why: CheckoutNotify, |
| 184 | path: str, |
| 185 | baseline: Optional[DiffFile], |
| 186 | target: Optional[DiffFile], |
| 187 | workdir: Optional[DiffFile], |
| 188 | ) -> None: |
| 189 | self.invoked_times += 1 |
| 190 | # skip one file so we're certain that NO files are affected, |
| 191 | # even if aborting the checkout from the second file |
| 192 | if self.invoked_times == 2: |
| 193 | raise InterruptedError('Stop the checkout!') |
| 194 | |
| 195 | head_object = testrepo.head |
| 196 | head = testrepo[head_object.target] |
| 197 | assert 'new' not in head.tree |
| 198 | assert b'bye world\n' == read_bye_txt() |
| 199 | callbacks = MyCheckoutCallbacks() |
| 200 | |
| 201 | # checkout i18n with GIT_CHECKOUT_FORCE - callbacks should prevent checkout from completing |
| 202 | with pytest.raises(InterruptedError): |
| 203 | testrepo.checkout( |
| 204 | ref_i18n, strategy=CheckoutStrategy.FORCE, callbacks=callbacks |
| 205 | ) |
| 206 | |
| 207 | assert callbacks.invoked_times == 2 |
| 208 | assert 'new' not in head.tree |
| 209 | assert b'bye world\n' == read_bye_txt() |
| 210 | |
| 211 | |
| 212 | def test_checkout_branch(testrepo: Repository) -> None: |
nothing calls this directly
no test coverage detected
searching dependent graphs…