Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ public GitInfo getGitInfo(@Nullable String repositoryPath) {
if (repositoryPath == null) {
repositoryPath = NULL_PATH_STRING;
}
return gitInfoCache.computeIfAbsent(repositoryPath, this::buildGitInfo);

// normalize path to avoid creating two entries in the cache
return gitInfoCache.computeIfAbsent(Paths.get(repositoryPath).toString(), this::buildGitInfo);
}

private GitInfo buildGitInfo(String repositoryPath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,25 @@ class GitInfoProviderTest extends Specification {
actualGitInfo.repositoryURL == "http://usefulUrl"
}

def "test caches git info regardless of path normalization"() {
setup:
def gitInfo = new GitInfo("repoUrl", "branch", "tag", new CommitInfo("sha"))
def gitInfoBuilder = Mock(GitInfoBuilder)
gitInfoBuilder.order() >> 1
gitInfoBuilder.providerAsExpected() >> GitProviderExpected.USER_SUPPLIED
gitInfoBuilder.providerAsDiscrepant() >> GitProviderDiscrepant.USER_SUPPLIED

def gitInfoProvider = new GitInfoProvider()
gitInfoProvider.registerGitInfoBuilder(gitInfoBuilder)

when:
gitInfoProvider.getGitInfo(REPO_PATH)
gitInfoProvider.getGitInfo(REPO_PATH + File.separator)

then:
1 * gitInfoBuilder.build(REPO_PATH) >> gitInfo
}

private GitInfoBuilder givenABuilderReturning(GitInfo gitInfo) {
givenABuilderReturning(gitInfo, 1)
}
Expand Down
Loading