Skip to content

Commit eab163e

Browse files
committed
Implement branch renames
1 parent 478cc34 commit eab163e

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/TfvcMigrator/Program.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ private static async IAsyncEnumerable<MappingState> EnumerateMappingStatesAsync(
483483
var mapping = branchMappings[branch.SourceBranch];
484484

485485
mapping = PathUtils.IsOrContains(branch.SourceBranchPath, mapping.RootDirectory)
486-
? mapping.RenameRootDirectory(branch.SourceBranchPath, branch.NewBranch.Path)
486+
? mapping.ApplyRename(branch.SourceBranchPath, branch.NewBranch.Path)
487487
: mapping.WithSubdirectoryMapping(branch.NewBranch.Path, branch.SourceBranchPath);
488488

489489
branchMappings.Add(branch.NewBranch, mapping);
@@ -505,7 +505,13 @@ private static async IAsyncEnumerable<MappingState> EnumerateMappingStatesAsync(
505505
case RenameOperation rename:
506506
{
507507
if (!branchMappings.Remove(rename.OldIdentity, out var mapping)) throw new NotImplementedException();
508-
branchMappings.Add(rename.NewIdentity, mapping.RenameRootDirectory(rename.OldIdentity.Path, rename.NewIdentity.Path));
508+
509+
foreach (var (otherBranch, otherMapping) in branchMappings.ToArray())
510+
{
511+
branchMappings[otherBranch] = otherMapping.ApplyRename(rename.OldIdentity.Path, rename.NewIdentity.Path);
512+
}
513+
514+
branchMappings.Add(rename.NewIdentity, mapping.ApplyRename(rename.OldIdentity.Path, rename.NewIdentity.Path));
509515

510516
if (trunk == rename.OldIdentity) trunk = rename.NewIdentity;
511517
break;

src/TfvcMigrator/RepositoryBranchMapping.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,19 @@ public RepositoryBranchMapping(string rootDirectory, (string BranchDirectory, st
4242
/// </summary>
4343
public (string BranchDirectory, string TargetDirectory)? SubdirectoryMapping { get; }
4444

45-
public RepositoryBranchMapping RenameRootDirectory(string oldPath, string newPath)
45+
public RepositoryBranchMapping ApplyRename(string oldPath, string newPath)
4646
{
4747
if (!PathUtils.IsAbsolute(oldPath))
4848
throw new ArgumentException("Old path must be absolute.", nameof(oldPath));
4949

5050
if (!PathUtils.IsAbsolute(newPath))
5151
throw new ArgumentException("New path must be absolute.", nameof(newPath));
5252

53-
if (!PathUtils.IsOrContains(RootDirectory, oldPath))
54-
throw new InvalidOperationException("The rename does not apply to this mapping.");
55-
56-
if (SubdirectoryMapping is not null)
57-
throw new NotImplementedException("Research: Renaming and branching might behave differently when subdirectory mapping is involved.");
58-
5953
return new RepositoryBranchMapping(
6054
PathUtils.ReplaceContainingPath(RootDirectory, oldPath, newPath),
61-
subdirectoryMapping: null);
55+
SubdirectoryMapping is null ? null : (
56+
PathUtils.ReplaceContainingPath(SubdirectoryMapping.Value.BranchDirectory, oldPath, newPath),
57+
PathUtils.ReplaceContainingPath(SubdirectoryMapping.Value.TargetDirectory, oldPath, newPath)));
6258
}
6359

6460
public RepositoryBranchMapping WithSubdirectoryMapping(string branchDirectory, string targetDirectory)

0 commit comments

Comments
 (0)