Skip to content

Commit ba4a6a8

Browse files
committed
fix(git): Improve the logic to determine the remote URL
Also support "unnamed" remotes that are URLs. Such remotes are for example created by the GitHub CLI when running `gh pr checkout ...`. Signed-off-by: Sebastian Schuberth <[email protected]>
1 parent 3d14c8c commit ba4a6a8

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

plugins/version-control-systems/git/src/main/kotlin/GitWorkingTree.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ import org.eclipse.jgit.submodule.SubmoduleWalk
3535
import org.ossreviewtoolkit.downloader.WorkingTree
3636
import org.ossreviewtoolkit.model.VcsInfo
3737
import org.ossreviewtoolkit.model.VcsType
38+
import org.ossreviewtoolkit.utils.common.toUri
39+
import org.ossreviewtoolkit.utils.ort.normalizeVcsUrl
3840

3941
private fun findGitOrSubmoduleDir(workingDirOrFile: File): Repository {
4042
val workingDir = (workingDirOrFile.takeIf { it.isDirectory } ?: workingDirOrFile.parentFile).absoluteFile
@@ -109,7 +111,7 @@ internal open class GitWorkingTree(workingDir: File, vcsType: VcsType) : Working
109111

110112
val firstRemote = remote?.urIs?.firstOrNull()
111113
when {
112-
firstRemote == null -> ""
114+
firstRemote == null -> normalizeVcsUrl(remoteForCurrentBranch).toUri { it.toString() }.getOrThrow()
113115
firstRemote.isRemote -> firstRemote.toString()
114116
else -> File(firstRemote.path).invariantSeparatorsPath
115117
}

0 commit comments

Comments
 (0)