Skip to content

Commit df1c995

Browse files
committed
scm4j/scm4j-releaser/Strip http(s) prefix from repo folder name #32
1 parent 899321b commit df1c995

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
import java.io.File;
44
import java.io.IOException;
5+
import java.util.Collections;
56

67
public class VCSRepositoryWorkspace implements IVCSRepositoryWorkspace {
78

9+
private static final String UNPRINTABLE_CHAR_PLACEHOLDER = "_";
10+
private static final String HTTP_PREFIX = "http" + String.join("", Collections.nCopies(3, UNPRINTABLE_CHAR_PLACEHOLDER));
11+
private static final String HTTPS_PREFIX = "https" + String.join("", Collections.nCopies(3, UNPRINTABLE_CHAR_PLACEHOLDER));
812
private final IVCSWorkspace workspace;
913
private final String repoUrl;
1014
private File repoFolder;
@@ -26,7 +30,12 @@ public IVCSLockedWorkingCopy getVCSLockedWorkingCopy() throws IOException {
2630
}
2731

2832
private String getRepoFolderName() {
29-
String tmp = repoUrl.replaceAll("[^a-zA-Z0-9.-]", "_");
33+
String tmp = repoUrl.replaceAll("[^a-zA-Z0-9.-]", UNPRINTABLE_CHAR_PLACEHOLDER);
34+
if (tmp.toLowerCase().startsWith(HTTPS_PREFIX)) {
35+
tmp = tmp.substring(HTTPS_PREFIX.length());
36+
} else if (tmp.toLowerCase().startsWith(HTTP_PREFIX)) {
37+
tmp = tmp.substring(HTTP_PREFIX.length());
38+
}
3039
return new File(workspace.getHomeFolder(), tmp).getPath().replace("\\", File.separator);
3140
}
3241

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,17 @@ public void testToString() {
3030
IVCSRepositoryWorkspace r = w.getVCSRepositoryWorkspace(TEST_REPO_URL);
3131
assertTrue(r.toString().contains(WORKSPACE_DIR));
3232
}
33+
34+
@Test
35+
public void testHTTPAndHTTPSFolderPrefixesStripping() {
36+
IVCSWorkspace w = new VCSWorkspace(WORKSPACE_DIR);
37+
String repoUrl = "test.repo.url";
38+
String httpProto = "http://";
39+
String httpsProto = "https://";
40+
IVCSRepositoryWorkspace r = w.getVCSRepositoryWorkspace(httpProto + repoUrl);
41+
assertEquals(repoUrl, r.getRepoFolder().getName());
42+
43+
r = w.getVCSRepositoryWorkspace(httpsProto + repoUrl);
44+
assertEquals(repoUrl, r.getRepoFolder().getName());
45+
}
3346
}

0 commit comments

Comments
 (0)