Context manager that checks out a given commit when entered, but gets back to the reference it was at on exit. Args: repo (`git.Repo`): A git repository (for instance the Transformers repo). commit_id (`str`): The commit reference to checkout inside the context manager.
(repo: Repo, commit_id: str)
| 86 | |
| 87 | @contextmanager |
| 88 | def checkout_commit(repo: Repo, commit_id: str): |
| 89 | """ |
| 90 | Context manager that checks out a given commit when entered, but gets back to the reference it was at on exit. |
| 91 | |
| 92 | Args: |
| 93 | repo (`git.Repo`): A git repository (for instance the Transformers repo). |
| 94 | commit_id (`str`): The commit reference to checkout inside the context manager. |
| 95 | """ |
| 96 | current_head = repo.head.commit if repo.head.is_detached else repo.head.ref |
| 97 | |
| 98 | try: |
| 99 | repo.git.checkout(commit_id) |
| 100 | yield |
| 101 | |
| 102 | finally: |
| 103 | repo.git.checkout(current_head) |
| 104 | |
| 105 | |
| 106 | def clean_code(content: str) -> str: |
no outgoing calls
no test coverage detected
searching dependent graphs…