Skip to content

Commit

Permalink
Enhance normalize uri
Browse files Browse the repository at this point in the history
Normalize uri like
[email protected]:errai/errai.git/errai-common
into
git://github.com/errai/errai.git

There are 3 independent operations:
1) set git:// instead git@
2) set github.com/ instead github:
3) remove tail after .git
  • Loading branch information
scabanovich committed Mar 23, 2016
1 parent af764de commit 72dbf59
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,28 @@ protected String normalizeUri(String uri) throws URISyntaxException {
throw new URISyntaxException(uri, "Invalid git URI");
}

// Normalize uri like
// [email protected]:errai/errai.git/errai-common
// into
// git://github.com/errai/errai.git
// These 3 distinctions may happen independently in other cases.
//1. Replace @ with ://
if(uri.startsWith("git@")) {
uri = "git://" + uri.substring(4);
}
//2. Replace github.com: with github.com/
String githubDotCom = "github.com";
int pos = uri.indexOf(githubDotCom + ":");
if(pos > 0) {
pos += githubDotCom.length();
uri = uri.substring(0, pos) + "/" + uri.substring(pos + 1);
}
//3. Remove tail after .git
int dotGit = uri.indexOf(".git");
if(dotGit >= 0 && uri.length() > dotGit + 4) {
uri = uri.substring(0, dotGit + 4);
}

URIish gitUri = new URIish(uri);
if(gitUri.getScheme() == null) {
if(gitUri.getHost() == null || "file".equals(gitUri.getHost())) {
Expand Down

0 comments on commit 72dbf59

Please sign in to comment.