Skip to content

Commit 478cc34

Browse files
committed
Make ReplaceContainingPath return the original path if it is not contained by the specified containing path
1 parent b3d389e commit 478cc34

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/TfvcMigrator/PathUtils.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ public static string GetLeaf(string path)
5353
return index == -1 ? path : path[(index + 1)..];
5454
}
5555

56+
/// <summary>
57+
/// If <paramref name="path"/> is or starts with <paramref name="containingPath"/>, <paramref
58+
/// name="containingPath"/> is replaced with <paramref name="newContainingPath"/> in the returned path. Otherwise,
59+
/// the unmodified <paramref name="path"/> is returned.
60+
/// </summary>
61+
/// <exception cref="ArgumentException">Thrown if any of the paths ends with a trailing slash.</exception>
5662
public static string ReplaceContainingPath(string path, string containingPath, string newContainingPath)
5763
{
5864
if (path.EndsWith('/'))
@@ -65,11 +71,16 @@ public static string ReplaceContainingPath(string path, string containingPath, s
6571
throw new ArgumentException("Path should not end with a trailing slash.", nameof(newContainingPath));
6672

6773
if (!IsOrContains(containingPath, path))
68-
throw new ArgumentException("The specified containing path does not contain the specified path.");
74+
return path;
6975

7076
return newContainingPath + path[containingPath.Length..];
7177
}
7278

79+
/// <summary>
80+
/// If <paramref name="path"/> is or starts with <paramref name="containingPath"/>, the relative part of the path
81+
/// (if any) is returned. Otherwise, <see cref="ArgumentException"/> is thrown.
82+
/// </summary>
83+
/// <exception cref="ArgumentException">Thrown if any of the paths ends with a trailing slash.</exception>
7384
public static string RemoveContainingPath(string path, string containingPath)
7485
{
7586
if (path.EndsWith('/'))

src/TfvcMigrator/RepositoryBranchMapping.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ public RepositoryBranchMapping WithSubdirectoryMapping(string branchDirectory, s
7676
if (PathUtils.IsOrContains(target, itemPath))
7777
return null;
7878

79-
if (PathUtils.IsOrContains(branch, itemPath))
80-
itemPath = PathUtils.ReplaceContainingPath(itemPath, branch, target);
79+
itemPath = PathUtils.ReplaceContainingPath(itemPath, branch, target);
8180
}
8281

8382
return PathUtils.IsOrContains(RootDirectory, itemPath)

0 commit comments

Comments
 (0)