Finds commit with given frid mentioned in the commit message and reverts the branch to it. If frid argument is not provided (None), repo is reverted to the initial state. In case the base folder doesn't exist, code is reverted to the initial repo commit. Otherwise, the repo is reverted
(repo_path: Union[str, os.PathLike], frid: Optional[str] = None)
| 145 | |
| 146 | |
| 147 | def revert_to_commit_with_frid(repo_path: Union[str, os.PathLike], frid: Optional[str] = None) -> Repo: |
| 148 | """ |
| 149 | Finds commit with given frid mentioned in the commit message and reverts the branch to it. |
| 150 | |
| 151 | If frid argument is not provided (None), repo is reverted to the initial state. In case the base folder doesn't exist, |
| 152 | code is reverted to the initial repo commit. Otherwise, the repo is reverted to the base folder commit. |
| 153 | |
| 154 | It is expected that the repo has at least one commit related to provided frid if frid is not None. |
| 155 | In case the frid related commit is not found, an exception is raised. |
| 156 | """ |
| 157 | repo = Repo(repo_path) |
| 158 | |
| 159 | commit = _get_commit(repo, frid) |
| 160 | |
| 161 | if not commit: |
| 162 | raise InvalidGitRepositoryError("Git repository is in an invalid state. Relevant commit could not be found.") |
| 163 | |
| 164 | repo.git.reset("--hard", commit) |
| 165 | repo.git.clean("-xdf") |
| 166 | return repo |
| 167 | |
| 168 | |
| 169 | def checkout_commit_with_frid(repo_path: Union[str, os.PathLike], frid: Optional[str] = None) -> Repo: |