Get the git diff between the current code state and the previous frid using git's native diff command. If previous_frid is not provided, we try to find the commit related to the copy of the base folder. Removes the 'diff --git' and 'index' lines to get clean unified diff format. A
(repo_path: Union[str, os.PathLike], previous_frid: str = None)
| 252 | |
| 253 | |
| 254 | def diff(repo_path: Union[str, os.PathLike], previous_frid: str = None) -> dict: |
| 255 | """ |
| 256 | Get the git diff between the current code state and the previous frid using git's native diff command. |
| 257 | If previous_frid is not provided, we try to find the commit related to the copy of the base folder. |
| 258 | Removes the 'diff --git' and 'index' lines to get clean unified diff format. |
| 259 | |
| 260 | |
| 261 | Args: |
| 262 | repo_path (str | os.PathLike): Path to the git repository |
| 263 | previous_frid (str): functionality ID (FRID) of the previous commit |
| 264 | |
| 265 | Returns: |
| 266 | dict: Dictionary with file names as keys and their clean diff strings as values |
| 267 | """ |
| 268 | repo = Repo(repo_path) |
| 269 | |
| 270 | commit = _get_commit(repo, previous_frid) |
| 271 | |
| 272 | # Add all files to the index to get a clean diff |
| 273 | repo.git.add("-N", ".") |
| 274 | |
| 275 | # Get the raw git diff output, excluding .pyc files |
| 276 | diff_output = repo.git.diff(commit, "--text", ":!*.pyc") |
| 277 | |
| 278 | if not diff_output: |
| 279 | return {} |
| 280 | |
| 281 | return _get_diff_dict(diff_output) |
| 282 | |
| 283 | |
| 284 | def _get_commit(repo: Repo, frid: Optional[str]) -> str: |