Clean all uncommitted changes. If base_commit is provided, reset to that commit. Then apply the patch to the codebase.
(self, patch: str, *, base_commit: str = "", filter_patch: bool = True)
| 145 | "git push origin --tags", |
| 146 | ]: |
| 147 | assert_zero_exit_code(self.environment.execute(cmd), logger=self.logger) |
| 148 | self.logger.info(f"Pushed {self.name} commit history to remote repository (branch {self._branch_name})") |
| 149 | |
| 150 | @abstractmethod |
| 151 | def run(self) -> None: |
| 152 | """Given the observation / recap, update the codebase""" |
| 153 | |
| 154 | def get_metadata(self) -> dict: |
| 155 | """Get metadata for the agent.""" |
| 156 | return self._metadata |
| 157 | |
| 158 | def reset_and_apply_patch(self, patch: str, *, base_commit: str = "", filter_patch: bool = True) -> None: |
| 159 | """Clean all uncommitted changes. If base_commit is provided, reset to that commit. |
| 160 | Then apply the patch to the codebase. |
| 161 | """ |
| 162 | # Need to clean before we copy over the patch (else it's gonna be removed by git clean) |
| 163 | self.logger.debug( |
| 164 | assert_zero_exit_code(self.environment.execute(f"git reset --hard {base_commit} && git clean -fd")) |
| 165 | ) |
| 166 | |
| 167 | patch = filter_git_diff(patch) if filter_patch else patch |
| 168 | |
| 169 | if not patch.strip(): |
| 170 | self.logger.debug("No patch to apply, skipping") |
| 171 | return |
| 172 | |
| 173 | create_file_in_container( |
| 174 | container=self.environment, # type: ignore |
no test coverage detected