MCPcopy Index your code
hub / github.com/CodeClash-ai/CodeClash / reset_and_apply_patch

Method reset_and_apply_patch

codeclash/agents/player.py:147–171  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 3

evaluateMethod · 0.80

Calls 4

assert_zero_exit_codeFunction · 0.90
filter_git_diffFunction · 0.90
create_file_in_containerFunction · 0.90
executeMethod · 0.45

Tested by

no test coverage detected