|
17 | 17 | in_directory, |
18 | 18 | safe_rm, |
19 | 19 | ) |
20 | | -from dfetch.vcs.patch import filter_patch |
| 20 | +from dfetch.vcs.patch import combine_patches, filter_patch, unified_diff_new_file |
21 | 21 |
|
22 | 22 | logger = get_logger(__name__) |
23 | 23 |
|
@@ -379,8 +379,40 @@ def get_diff( |
379 | 379 | with in_directory(self.local_path): |
380 | 380 | patch_text = run_on_cmdline(logger, cmd).stdout |
381 | 381 |
|
382 | | - return filter_patch(patch_text, ignore) |
| 382 | + filtered = filter_patch(patch_text, ignore) |
| 383 | + |
| 384 | + if new_revision: |
| 385 | + return filtered |
| 386 | + |
| 387 | + patches: list[bytes] = [filtered.encode("utf-8")] if filtered else [] |
| 388 | + with in_directory(self.local_path): |
| 389 | + for file_path in self._untracked_not_ignored("."): |
| 390 | + diff = unified_diff_new_file(pathlib.Path(file_path)) |
| 391 | + if diff: |
| 392 | + patch = [f"Index: {file_path}", "=" * 67] + diff |
| 393 | + |
| 394 | + print(patch) |
| 395 | + patches.append("\n".join(patch).encode("utf-8")) |
| 396 | + |
| 397 | + return combine_patches(patches) |
383 | 398 |
|
384 | 399 | def get_default_branch(self) -> str: |
385 | 400 | """Get the default branch of this repository.""" |
386 | 401 | return self.DEFAULT_BRANCH |
| 402 | + |
| 403 | + @staticmethod |
| 404 | + def _untracked_not_ignored(path: str) -> list[str]: |
| 405 | + result = ( |
| 406 | + run_on_cmdline( |
| 407 | + logger, |
| 408 | + ["svn", "status", "--no-ignore", path], |
| 409 | + ) |
| 410 | + .stdout.decode() |
| 411 | + .splitlines() |
| 412 | + ) |
| 413 | + |
| 414 | + files = [] |
| 415 | + for line in result: |
| 416 | + if line.startswith("?"): |
| 417 | + files.append(line[1:].strip()) |
| 418 | + return files |
0 commit comments