Skip to content

Commit 7b5f06b

Browse files
committed
* scm4j/scm4j-releaser/Strip http(s) prefix from repo folder name #32
file:// stripping added
1 parent 5d0d529 commit 7b5f06b

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/main/java/org/scm4j/vcs/api/workingcopy/VCSRepositoryWorkspace.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ public class VCSRepositoryWorkspace implements IVCSRepositoryWorkspace {
99
private static final String UNPRINTABLE_CHAR_PLACEHOLDER = "_";
1010
private static final String HTTP_PREFIX = "http" + String.join("", Collections.nCopies(3, UNPRINTABLE_CHAR_PLACEHOLDER));
1111
private static final String HTTPS_PREFIX = "https" + String.join("", Collections.nCopies(3, UNPRINTABLE_CHAR_PLACEHOLDER));
12+
private static final String FILE_PREFIX_1 = "file" + String.join("", Collections.nCopies(2, UNPRINTABLE_CHAR_PLACEHOLDER));
13+
private static final String FILE_PREFIX_2 = "file" + String.join("", Collections.nCopies(3, UNPRINTABLE_CHAR_PLACEHOLDER));
14+
private static final String FILE_PREFIX_3 = "file" + String.join("", Collections.nCopies(4, UNPRINTABLE_CHAR_PLACEHOLDER));
1215
private final IVCSWorkspace workspace;
1316
private final String repoUrl;
1417
private File repoFolder;
@@ -35,6 +38,12 @@ private String getRepoFolderName() {
3538
tmp = tmp.substring(HTTPS_PREFIX.length());
3639
} else if (tmp.toLowerCase().startsWith(HTTP_PREFIX)) {
3740
tmp = tmp.substring(HTTP_PREFIX.length());
41+
} else if (tmp.toLowerCase().startsWith(FILE_PREFIX_3)) {
42+
tmp = tmp.substring(FILE_PREFIX_3.length());
43+
} else if (tmp.toLowerCase().startsWith(FILE_PREFIX_2)) {
44+
tmp = tmp.substring(FILE_PREFIX_2.length());
45+
} else if (tmp.toLowerCase().startsWith(FILE_PREFIX_1)) {
46+
tmp = tmp.substring(FILE_PREFIX_1.length());
3847
}
3948
return new File(workspace.getHomeFolder(), tmp).getPath().replace("\\", File.separator);
4049
}

src/test/java/org/scm4j/vcs/api/workingcopy/VCSRepositoryWorkspaceTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,23 @@ public void testHTTPAndHTTPSFolderPrefixesStripping() {
3737
String repoUrl = "test.repo.url";
3838
String httpProto = "http://";
3939
String httpsProto = "https://";
40+
String fileProto1 = "file:/";
41+
String fileProto2 = "file://";
42+
String fileProto3 = "file:///";
43+
4044
IVCSRepositoryWorkspace r = w.getVCSRepositoryWorkspace(httpProto + repoUrl);
4145
assertEquals(repoUrl, r.getRepoFolder().getName());
4246

4347
r = w.getVCSRepositoryWorkspace(httpsProto + repoUrl);
4448
assertEquals(repoUrl, r.getRepoFolder().getName());
49+
50+
r = w.getVCSRepositoryWorkspace(fileProto1 + repoUrl);
51+
assertEquals(repoUrl, r.getRepoFolder().getName());
52+
53+
r = w.getVCSRepositoryWorkspace(fileProto2 + repoUrl);
54+
assertEquals(repoUrl, r.getRepoFolder().getName());
55+
56+
r = w.getVCSRepositoryWorkspace(fileProto3 + repoUrl);
57+
assertEquals(repoUrl, r.getRepoFolder().getName());
4558
}
4659
}

0 commit comments

Comments
 (0)