diff --git a/src/main/kotlin/uk/co/ben_gibson/git/link/git/RemoteExtensions.kt b/src/main/kotlin/uk/co/ben_gibson/git/link/git/RemoteExtensions.kt index 5e7e641..6fe241e 100644 --- a/src/main/kotlin/uk/co/ben_gibson/git/link/git/RemoteExtensions.kt +++ b/src/main/kotlin/uk/co/ben_gibson/git/link/git/RemoteExtensions.kt @@ -22,8 +22,8 @@ val GitRemote.httpUrl : URL? get() { url = url.removeSuffix(".git") } - // Do not try to remove the port if the URL uses the SSH protocol in the SCP syntax. For example - // 'git@github.com:foo.git'. This syntax does not support port definitions. Attempting to remove the port + // Do not try to remove the port if the URL uses the SSH protocol in the SCP syntax e.g. + // 'git@github.com:foo.git' as it does not support port definitions. Attempting to remove the port // will result in an invalid URL when the repository name is made up of digits. // See https://github.com/ben-gibson/GitLink/issues/94 if (!url.startsWith("git@")) { diff --git a/src/main/kotlin/uk/co/ben_gibson/git/link/platform/PlatformDetector.kt b/src/main/kotlin/uk/co/ben_gibson/git/link/platform/PlatformDetector.kt index 59ab922..e908d53 100644 --- a/src/main/kotlin/uk/co/ben_gibson/git/link/platform/PlatformDetector.kt +++ b/src/main/kotlin/uk/co/ben_gibson/git/link/platform/PlatformDetector.kt @@ -26,9 +26,7 @@ class PlatformDetector(val project: Project) { getRepositoryForFile(projectDirectory) { repository -> getPlatformForRepository(repository).let(consumer) } } - private fun getPlatformForRepository(repository: GitRepository?): Platform? { - repository ?: return null - + private fun getPlatformForRepository(repository: GitRepository): Platform? { val settings = project.service() val remote = repository.locateRemote(settings.remote) ?: return null @@ -41,7 +39,7 @@ class PlatformDetector(val project: Project) { } } - private fun getRepositoryForFile(projectDirectory: VirtualFile, consumer: (GitRepository?) -> Unit) { + private fun getRepositoryForFile(projectDirectory: VirtualFile, consumer: (GitRepository) -> Unit) { val gitRepositoryManager = GitRepositoryManager.getInstance(project) val repository = gitRepositoryManager.getRepositoryForFile(projectDirectory) if (repository != null) { @@ -55,7 +53,7 @@ class PlatformDetector(val project: Project) { VcsRepositoryManager.VCS_REPOSITORY_MAPPING_UPDATED, VcsRepositoryMappingListener { busConnection.disconnect() - gitRepositoryManager.getRepositoryForFile(projectDirectory).let(consumer) + gitRepositoryManager.getRepositoryForFile(projectDirectory)?.let(consumer) } ) } diff --git a/src/main/kotlin/uk/co/ben_gibson/git/link/url/template/UrlTemplates.kt b/src/main/kotlin/uk/co/ben_gibson/git/link/url/template/UrlTemplates.kt index 294b363..7610f79 100644 --- a/src/main/kotlin/uk/co/ben_gibson/git/link/url/template/UrlTemplates.kt +++ b/src/main/kotlin/uk/co/ben_gibson/git/link/url/template/UrlTemplates.kt @@ -12,9 +12,9 @@ data class UrlTemplates(val fileAtBranch: String, val fileAtCommit : String, val fun gitLab(): UrlTemplates { return UrlTemplates( - "{remote:url}/-/{object}/{branch}/{file:path}/{file:name}{line-block:start}#L{line:start}-{line:end}{line-block:end}", - "{remote:url}/-/{object}/{commit}/{file:path}/{file:name}{line-block:start}#L{line:start}-{line:end}{line-block:end}", - "{remote:url}/-/commit/{commit}" + "{remote:url}/{object}/{branch}/{file:path}/{file:name}{line-block:start}#L{line:start}-{line:end}{line-block:end}", + "{remote:url}/{object}/{commit}/{file:path}/{file:name}{line-block:start}#L{line:start}-{line:end}{line-block:end}", + "{remote:url}/commit/{commit}" ) } diff --git a/src/test/kotlin/uk/co/ben_gibson/git/link/url/GitLabTest.kt b/src/test/kotlin/uk/co/ben_gibson/git/link/url/GitLabTest.kt index 3c4d1f5..3c1f0ae 100644 --- a/src/test/kotlin/uk/co/ben_gibson/git/link/url/GitLabTest.kt +++ b/src/test/kotlin/uk/co/ben_gibson/git/link/url/GitLabTest.kt @@ -26,15 +26,15 @@ class GitLabTest { fun urlExpectationsProvider(): Stream = Stream.of( Arguments.of( UrlOptionsFileAtBranch(REMOTE_BASE_URL, FILE, BRANCH, LINE_SELECTION), - "https://gitlab.com/my/repo/-/blob/master/src/Foo.java#L10-20" + "https://gitlab.com/my/repo/blob/master/src/Foo.java#L10-20" ), Arguments.of( UrlOptionsFileAtBranch(REMOTE_BASE_URL, FILE, BRANCH), - "https://gitlab.com/my/repo/-/blob/master/src/Foo.java" + "https://gitlab.com/my/repo/blob/master/src/Foo.java" ), Arguments.of( UrlOptionsFileAtCommit(REMOTE_BASE_URL, FILE, COMMIT, LineSelection(10, 20)), - "https://gitlab.com/my/repo/-/blob/b032a0707beac9a2f24b1b7d97ee4f7156de182c/src/Foo.java#L10-20" + "https://gitlab.com/my/repo/blob/b032a0707beac9a2f24b1b7d97ee4f7156de182c/src/Foo.java#L10-20" ), Arguments.of( UrlOptionsFileAtBranch( @@ -43,7 +43,7 @@ class GitLabTest { BRANCH, LINE_SELECTION ), - "https://gitlab.com/my/repo/-/blob/master/Assets/%23/Sources/Code.cs#L10-20" + "https://gitlab.com/my/repo/blob/master/Assets/%23/Sources/Code.cs#L10-20" ), Arguments.of( UrlOptionsFileAtCommit( @@ -51,7 +51,7 @@ class GitLabTest { File("resources", true, "src/foo", false), COMMIT ), - "https://gitlab.com/my/repo/-/tree/b032a0707beac9a2f24b1b7d97ee4f7156de182c/src/foo/resources" + "https://gitlab.com/my/repo/tree/b032a0707beac9a2f24b1b7d97ee4f7156de182c/src/foo/resources" ), Arguments.of( UrlOptionsFileAtCommit( @@ -59,15 +59,15 @@ class GitLabTest { File("my-project", true, "", true), COMMIT ), - "https://gitlab.com/my/repo/-/tree/b032a0707beac9a2f24b1b7d97ee4f7156de182c" + "https://gitlab.com/my/repo/tree/b032a0707beac9a2f24b1b7d97ee4f7156de182c" ), Arguments.of( UrlOptionsFileAtCommit(REMOTE_BASE_URL, FILE, COMMIT), - "https://gitlab.com/my/repo/-/blob/b032a0707beac9a2f24b1b7d97ee4f7156de182c/src/Foo.java" + "https://gitlab.com/my/repo/blob/b032a0707beac9a2f24b1b7d97ee4f7156de182c/src/Foo.java" ), Arguments.of( UrlOptionsCommit(REMOTE_BASE_URL, COMMIT), - "https://gitlab.com/my/repo/-/commit/b032a0707beac9a2f24b1b7d97ee4f7156de182c" + "https://gitlab.com/my/repo/commit/b032a0707beac9a2f24b1b7d97ee4f7156de182c" ) ) }