Skip to content

Commit

Permalink
[patch] continuing transition to adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
robertfmurdock committed Sep 19, 2024
1 parent de18a78 commit 5c7d5b5
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class AllPathsTest {

@Test
fun willHandleSimplePathsEasily() {
val grgit = initializeGitRepo(
val (grgit, _) = initializeGitRepo(
directory = projectDir.absolutePath,
commits = listOf("first"),
addFileNames = emptySet(),
Expand Down Expand Up @@ -54,7 +54,7 @@ class AllPathsTest {

@Test
fun willIgnoreBranchesWhenOneParentIsInPreferredList() {
val grgit = initializeGitRepo(
val (grgit, _) = initializeGitRepo(
directory = projectDir.absolutePath,
commits = listOf("first"),
addFileNames = emptySet(),
Expand Down Expand Up @@ -85,7 +85,7 @@ class AllPathsTest {

@Test
fun branchMergeBranchMergeFindsAllPaths() {
val grgit = initializeGitRepo(
val (grgit, _) = initializeGitRepo(
directory = projectDir.absolutePath,
commits = listOf("first"),
addFileNames = emptySet(),
Expand Down Expand Up @@ -221,7 +221,7 @@ class AllPathsTest {

@Test
fun willStopOnceFindingPathContainingAllPreferredCommits() {
val grgit = initializeGitRepo(
val (grgit, _) = initializeGitRepo(
directory = projectDir.absolutePath,
commits = listOf("first"),
addFileNames = emptySet(),
Expand Down Expand Up @@ -280,7 +280,7 @@ class AllPathsTest {

@Test
fun mergeToBranchAndBackFindsAllPaths() {
val grgit = initializeGitRepo(
val (grgit, _) = initializeGitRepo(
directory = projectDir.absolutePath,
commits = listOf("first"),
addFileNames = emptySet(),
Expand Down Expand Up @@ -329,7 +329,7 @@ class AllPathsTest {

@Test
fun branchOnBranchOnBranchFindsAllPaths() {
val grgit = initializeGitRepo(
val (grgit, _) = initializeGitRepo(
directory = projectDir.absolutePath,
commits = listOf("first"),
addFileNames = emptySet(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface AllContributionTestSpec : SetupWithOverrides {
@Test
fun `will include all tag segments`() {
setupWithDefaults()
val grgit = initializeGitRepo(
val (grgit, _) = initializeGitRepo(
listOf(
"""here's a message
|
Expand Down Expand Up @@ -83,7 +83,7 @@ interface AllContributionTestSpec : SetupWithOverrides {
@Test
fun `will consider the path with the most tags, the trunk`() {
setupWithDefaults()
val grgit = initializeGitRepo(listOf("here's a message"))
val (grgit, _) = initializeGitRepo(listOf("here's a message"))
val firstCommit = grgit.head()
val firstRelease = grgit.addTag("release1")
delayLongEnoughToAffectGitDate()
Expand Down Expand Up @@ -129,7 +129,7 @@ interface AllContributionTestSpec : SetupWithOverrides {
@Test
fun `will handle normal merge-into-branch-then-back case well`() {
setupWithDefaults()
val grgit = initializeGitRepo(listOf("here's a message"))
val (grgit, _) = initializeGitRepo(listOf("here's a message"))
val firstCommit = grgit.head()
val firstRelease = grgit.addTag("release")

Expand Down Expand Up @@ -172,7 +172,7 @@ interface AllContributionTestSpec : SetupWithOverrides {
@Test
fun `will handle normal merge-into-branch-then-ff-back case`() {
setupWithDefaults()
val grgit = initializeGitRepo(listOf("here's a message"))
val (grgit, _) = initializeGitRepo(listOf("here's a message"))
val firstCommit = grgit.head()
val firstRelease = grgit.addTag("release-1")

Expand Down Expand Up @@ -224,7 +224,7 @@ interface AllContributionTestSpec : SetupWithOverrides {
@Test
fun willHandleMergeBranches() {
setupWithDefaults()
val grgit = initializeGitRepo(listOf("first"))
val (grgit, _) = initializeGitRepo(listOf("first"))
val firstCommit = grgit.head()

val firstRelease = grgit.addTag("release")
Expand Down Expand Up @@ -273,7 +273,7 @@ interface AllContributionTestSpec : SetupWithOverrides {
setupWithOverrides(
tagRegex = "v(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?",
)
val grgit = initializeGitRepo(listOf("first"))
val (grgit, _) = initializeGitRepo(listOf("first"))
val firstCommit = grgit.head()

val firstRelease = grgit.addTag("v1.2.8")
Expand Down Expand Up @@ -315,7 +315,7 @@ interface AllContributionTestSpec : SetupWithOverrides {
@Test
fun `will handle merge commits on merged branches correctly`() {
setupWithDefaults()
val grgit = initializeGitRepo(listOf("first"))
val (grgit, _) = initializeGitRepo(listOf("first"))
val firstCommit = grgit.head()

val firstRelease = grgit.addTag("release")
Expand Down Expand Up @@ -362,7 +362,7 @@ interface AllContributionTestSpec : SetupWithOverrides {
@Test
fun `when merging multiple times from same branch, commits are only counted once`() {
setupWithDefaults()
val grgit = initializeGitRepo(listOf("first"))
val (grgit, _) = initializeGitRepo(listOf("first"))
val firstCommit = grgit.head()
val firstRelease = grgit.addTag("release")

Expand Down Expand Up @@ -437,14 +437,13 @@ interface AllContributionTestSpec : SetupWithOverrides {
@Test
fun `will include ease of change`() {
setupWithDefaults()
val grgit =
initializeGitRepo(
directory = projectDir.absolutePath,
addFileNames = addFileNames,
commits = listOf(
"here's a message -4- more stuff",
),
)
val (grgit, _) = initializeGitRepo(
directory = projectDir.absolutePath,
addFileNames = addFileNames,
commits = listOf(
"here's a message -4- more stuff",
),
)
val firstCommit = grgit.head()

val tag = grgit.addTag("release")
Expand Down Expand Up @@ -474,7 +473,7 @@ interface AllContributionTestSpec : SetupWithOverrides {
@Test
fun `will include story ids`() {
setupWithDefaults()
val grgit = initializeGitRepo(commits = listOf("[DOGCOW-17] here's a message"))
val (grgit, _) = initializeGitRepo(commits = listOf("[DOGCOW-17] here's a message"))
val firstCommit = grgit.head()
val tag = grgit.addTag("release")
val secondCommit = grgit.addCommitWithMessage("[DOGCOW-18] -3- here's a message")
Expand All @@ -501,7 +500,7 @@ interface AllContributionTestSpec : SetupWithOverrides {
@Test
fun `will merge the same story id within a contribution`() {
setupWithDefaults()
val grgit = initializeGitRepo(listOf("[DOGCOW-17] here's a message"))
val (grgit, _) = initializeGitRepo(listOf("[DOGCOW-17] here's a message"))
val firstCommit = grgit.head()
val secondCommit = grgit.addCommitWithMessage("[DOGCOW-17] -3- here's a message")
val allOutput = runAllContributionData()
Expand All @@ -523,7 +522,7 @@ interface AllContributionTestSpec : SetupWithOverrides {
@Test
fun `will merge the different story ids within a contribution`() {
setupWithOverrides(label = "AwesomeProject")
val grgit = initializeGitRepo(commits = listOf("[DOGCOW-17] here's a message"))
val (grgit, _) = initializeGitRepo(commits = listOf("[DOGCOW-17] here's a message"))
val firstCommit = grgit.head()
val secondCommit = grgit.addCommitWithMessage("[DOGCOW-18] -3- here's a message")

Expand All @@ -548,7 +547,7 @@ interface AllContributionTestSpec : SetupWithOverrides {
@Test
fun `will include flatten ease into largest number`() {
setupWithDefaults()
val grgit = initializeGitRepo(listOf("here's a message -4- more stuff"))
val (grgit, _) = initializeGitRepo(listOf("here's a message -4- more stuff"))
val firstCommit = grgit.head()
val secondCommit = grgit.addCommitWithMessage("-3- here's a message")
val allOutput = runAllContributionData()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ interface CurrentContributionTestSpec : SetupWithOverrides {
fun `currentContributionData will include most recent tag range when head is tagged`() {
setupWithDefaults()

val grgit = initializeGitRepo(
val (grgit, _) = initializeGitRepo(
directory = projectDir.absolutePath,
addFileNames = addFileNames,
commits = listOf(
Expand Down Expand Up @@ -226,7 +226,7 @@ interface CurrentContributionTestSpec : SetupWithOverrides {
fun `when head is tagged currentContributionData will use include tag info`() {
setupWithDefaults()

val grgit = initializeGitRepo(
val (grgit, _) = initializeGitRepo(
directory = projectDir.absolutePath,
addFileNames = addFileNames,
commits = listOf(
Expand Down Expand Up @@ -268,19 +268,18 @@ interface CurrentContributionTestSpec : SetupWithOverrides {
fun `currentContributionData will not include authors from commits before last tag`() {
setupWithDefaults()

val grgit =
initializeGitRepo(
directory = projectDir.absolutePath,
addFileNames = addFileNames,
commits = listOf(
"""here's a message
val (grgit, _) = initializeGitRepo(
directory = projectDir.absolutePath,
addFileNames = addFileNames,
commits = listOf(
"""here's a message
|
|
|Co-authored-by: First Guy <[email protected]>
|Co-authored-by: Second Gui <[email protected]>
""".trimMargin(),
),
)
""".trimMargin(),
),
)

grgit.addTag("release")
grgit.addCommitWithMessage(
Expand Down Expand Up @@ -396,7 +395,7 @@ interface CurrentContributionTestSpec : SetupWithOverrides {
@Test
fun `will handle merge commits on merged branches correctly`() {
setupWithDefaults()
val grgit = initializeGitRepo(listOf("first"))
val (grgit, _) = initializeGitRepo(listOf("first"))
grgit.head()

grgit.addTag("release")
Expand Down Expand Up @@ -438,7 +437,7 @@ interface CurrentContributionTestSpec : SetupWithOverrides {
setupWithOverrides(
tagRegex = "v(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?",
)
val grgit = initializeGitRepo(listOf("first"))
val (grgit, _) = initializeGitRepo(listOf("first"))
grgit.head()

grgit.addTag("v1.0.0")
Expand Down Expand Up @@ -477,7 +476,7 @@ interface CurrentContributionTestSpec : SetupWithOverrides {
@Test
fun `will correctly understand longer running branch`() {
setupWithDefaults()
val grgit = initializeGitRepo(listOf("first"))
val (grgit, _) = initializeGitRepo(listOf("first"))
grgit.head()

grgit.addTag("release")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class GitAdapterTest {

@Test
fun `will include all tag segments from newest to oldest`() {
val grgit = initializeGitRepo(commits = listOf("here's a message"))
val (grgit, _) = initializeGitRepo(commits = listOf("here's a message"))
grgit.addTag("v1.0")
delayLongEnoughToAffectGitDate()
grgit.addCommitWithMessage("here's a message")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fun initializeGitRepo(
addFileNames: Set<String>,
commits: List<String> = listOf(),
initialTag: String? = null,
): Grgit {
): Pair<Grgit, GitAdapter> {
val gitAdapter = GitAdapter(directory)
gitAdapter.init()
gitAdapter.config("commit.gpgsign", "false")
Expand All @@ -42,7 +42,7 @@ fun initializeGitRepo(
this.mode = BranchChangeOp.Mode.TRACK
},
)
return grgit
return grgit to gitAdapter
}

fun Grgit.addTag(initialTag: String?): org.ajoberstar.grgit.Tag? = tag.add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ interface TagTestSpec {
originGrgit.commit(fun CommitOp.() {
this.message = "init"
})
val grgit = initializeGitRepo(
val (grgit, gitAdapter) = initializeGitRepo(
listOf("init", "[patch] commit 1", "[patch] commit 2"),
remoteUrl = originDirectory.absolutePathString(),
)
Expand All @@ -83,7 +83,6 @@ interface TagTestSpec {
val result = execute(expectedVersion)
assertIsNot<TestResult.Failure>(result, message = "$result")

val gitAdapter = GitAdapter(this.projectDir.absolutePath)
assertEquals(expectedVersion, gitAdapter.showTag("HEAD"))
}

Expand All @@ -109,7 +108,7 @@ interface TagTestSpec {
originGrgit.commit(fun CommitOp.() {
this.message = "init"
})
val grgit = initializeGitRepo(
val (grgit, gitAdapter) = initializeGitRepo(
listOf("init", "[patch] commit 1", "[patch] commit 2"),
remoteUrl = originDirectory.absolutePathString(),
)
Expand All @@ -119,7 +118,6 @@ interface TagTestSpec {
val result = execute(expectedVersion)
assertIsNot<TestResult.Failure>(result, message = "$result")

val gitAdapter = GitAdapter(this.projectDir.absolutePath)
assertEquals(expectedVersion, gitAdapter.showTag("HEAD"))
}

Expand All @@ -136,7 +134,7 @@ interface TagTestSpec {
originGrgit.commit(fun CommitOp.() {
this.message = "init"
})
val grgit = initializeGitRepo(
val (grgit, gitAdapter) = initializeGitRepo(
listOf("init", "[patch] commit 1", "[patch] commit 2"),
remoteUrl = originDirectory.absolutePathString(),
)
Expand All @@ -148,7 +146,6 @@ interface TagTestSpec {
charSequence = assertIs<TestResult.Failure>(result).reason,
other = "Committer identity unknown",
)
val gitAdapter = GitAdapter(this.projectDir.absolutePath)
assertNotEquals(version, gitAdapter.showTag("HEAD"))
}

Expand All @@ -165,7 +162,7 @@ interface TagTestSpec {
originGrgit.commit(fun CommitOp.() {
this.message = "init"
})
val grgit = initializeGitRepo(
val (grgit, gitAdapter) = initializeGitRepo(
listOf("init", "[patch] commit 1", "[patch] commit 2"),
remoteUrl = originDirectory.absolutePathString(),
)
Expand All @@ -180,7 +177,6 @@ interface TagTestSpec {
charSequence = assertIs<TestResult.Failure>(result).reason,
other = TagErrors.wrapper(TagErrors.skipMessageNotOnReleaseBranch("trunk", "master")),
)
val gitAdapter = GitAdapter(this.projectDir.absolutePath)
assertNotEquals(version, gitAdapter.showTag("HEAD"))
}

Expand All @@ -197,7 +193,7 @@ interface TagTestSpec {
originGrgit.commit(fun CommitOp.() {
this.message = "init"
})
val grgit = initializeGitRepo(
val (grgit, gitAdapter) = initializeGitRepo(
listOf("init", "[patch] commit 1", "[patch] commit 2"),
remoteUrl = originDirectory.absolutePathString(),
)
Expand All @@ -212,7 +208,6 @@ interface TagTestSpec {
charSequence = assertIs<TestResult.Success>(result).message,
other = TagErrors.wrapper(TagErrors.skipMessageNotOnReleaseBranch("trunk", "master")),
)
val gitAdapter = GitAdapter(this.projectDir.absolutePath)
assertNotEquals(version, gitAdapter.showTag("HEAD"))
}
}

0 comments on commit 5c7d5b5

Please sign in to comment.