Skip to content

Commit 87c2b19

Browse files
authored
Fix origin/ prefix being applied too many places (#122)
1 parent a434b89 commit 87c2b19

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

core/src/main/kotlin/xyz/block/artifactswap/core/download/services/ArtifactSyncBomLoader.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ class RealArtifactSyncBomLoader(
4242
}
4343

4444
override suspend fun findBestBomVersion(checkRemote: Boolean): Result<String> = runCatching {
45+
val bomBranch = config.bomSourceBranchName
46+
val originRef = if (bomBranch.startsWith("origin/")) bomBranch else "origin/$bomBranch"
4547
val recentSharedCommits =
4648
squareGit.findRecentSharedCommits(
47-
baseRef = config.bomSourceBranchName,
49+
baseRef = originRef,
4850
count = COUNT_SHARED_COMMITS_TO_CHECK_FOR_BOM,
4951
)
5052

@@ -54,7 +56,7 @@ class RealArtifactSyncBomLoader(
5456
}
5557
?: throw IllegalStateException(
5658
"Traversed $COUNT_SHARED_COMMITS_TO_CHECK_FOR_BOM commits " +
57-
"from ${config.bomSourceBranchName} and found no matching BOMs"
59+
"from $originRef and found no matching BOMs"
5860
)
5961
matchingBom.name
6062
}

core/src/main/kotlin/xyz/block/artifactswap/core/shared_services/git/SquareGit.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,9 @@ class RealSquareGit(rootDir: Path, private val context: CoroutineContext) : Squa
7171
}
7272

7373
override suspend fun findRecentSharedCommits(baseRef: String, count: Int): List<ObjectId> {
74-
val originRef = if (baseRef.startsWith("origin/")) baseRef else "origin/$baseRef"
75-
LOGGER.info("Finding merge base between $originRef and ${Constants.HEAD}")
74+
LOGGER.info("Finding merge base between $baseRef and ${Constants.HEAD}")
7675
val baseCommit =
77-
repository.resolve(originRef)
78-
?: throw IllegalStateException("$originRef could not be resolved")
76+
repository.resolve(baseRef) ?: throw IllegalStateException("$baseRef could not be resolved")
7977
val headCommit =
8078
repository.resolve(Constants.HEAD)
8179
?: throw IllegalStateException("${Constants.HEAD} could not be resolved")
@@ -90,7 +88,7 @@ class RealSquareGit(rootDir: Path, private val context: CoroutineContext) : Squa
9088
}
9189
}
9290
if (mergeBase == null) {
93-
throw IllegalStateException("No merge base found between $originRef and ${Constants.HEAD}")
91+
throw IllegalStateException("No merge base found between $baseRef and ${Constants.HEAD}")
9492
}
9593
val commits = git.log().add(mergeBase).call().take(count).map { it.id }
9694
return commits
@@ -107,7 +105,7 @@ class RealSquareGit(rootDir: Path, private val context: CoroutineContext) : Squa
107105
@OptIn(ExperimentalCoroutinesApi::class)
108106
override suspend fun findChangedFiles(baseRef: String): Result<Set<Path>> = runCatching {
109107
val baseCommit =
110-
findRecentSharedCommits(baseRef)?.first()
108+
findRecentSharedCommits(baseRef).firstOrNull()
111109
?: throw IllegalStateException("No recent shared commits found")
112110
LOGGER.debug("Got comparison labels: {}", getComparisonLabels(baseCommit))
113111

0 commit comments

Comments
 (0)