|
17 | 17 | in_directory, |
18 | 18 | safe_rm, |
19 | 19 | ) |
20 | | -from dfetch.vcs.patch import filter_patch |
| 20 | +from dfetch.vcs.patch import ( |
| 21 | + combine_patches, |
| 22 | + create_svn_patch_for_new_file, |
| 23 | + filter_patch, |
| 24 | +) |
21 | 25 |
|
22 | 26 | logger = get_logger(__name__) |
23 | 27 |
|
@@ -372,15 +376,52 @@ def get_diff( |
372 | 376 | self, old_revision: str, new_revision: Optional[str], ignore: Sequence[str] |
373 | 377 | ) -> str: |
374 | 378 | """Get the diff between two revisions.""" |
375 | | - cmd = ["svn", "diff", "--non-interactive", ".", "-r", old_revision] |
| 379 | + cmd = [ |
| 380 | + "svn", |
| 381 | + "diff", |
| 382 | + "--non-interactive", |
| 383 | + "--ignore-properties", |
| 384 | + ".", |
| 385 | + "-r", |
| 386 | + old_revision, |
| 387 | + ] |
376 | 388 | if new_revision: |
377 | 389 | cmd[-1] += f":{new_revision}" |
378 | 390 |
|
379 | 391 | with in_directory(self.local_path): |
380 | 392 | patch_text = run_on_cmdline(logger, cmd).stdout |
381 | 393 |
|
382 | | - return filter_patch(patch_text, ignore) |
| 394 | + filtered = filter_patch(patch_text, ignore) |
| 395 | + |
| 396 | + if new_revision: |
| 397 | + return filtered |
| 398 | + |
| 399 | + patches: list[bytes] = [filtered.encode("utf-8")] if filtered else [] |
| 400 | + with in_directory(self.local_path): |
| 401 | + for file_path in self._untracked_not_ignored("."): |
| 402 | + patch = create_svn_patch_for_new_file(file_path) |
| 403 | + if patch: |
| 404 | + patches.append(patch.encode("utf-8")) |
| 405 | + |
| 406 | + return combine_patches(patches) |
383 | 407 |
|
384 | 408 | def get_default_branch(self) -> str: |
385 | 409 | """Get the default branch of this repository.""" |
386 | 410 | return self.DEFAULT_BRANCH |
| 411 | + |
| 412 | + @staticmethod |
| 413 | + def _untracked_not_ignored(path: str) -> list[str]: |
| 414 | + result = ( |
| 415 | + run_on_cmdline( |
| 416 | + logger, |
| 417 | + ["svn", "status", path], |
| 418 | + ) |
| 419 | + .stdout.decode() |
| 420 | + .splitlines() |
| 421 | + ) |
| 422 | + |
| 423 | + files = [] |
| 424 | + for line in result: |
| 425 | + if line.startswith("?"): |
| 426 | + files.append(line[1:].strip()) |
| 427 | + return files |
0 commit comments