Files
Githug-Android/app/src/main/java/solutions/tretter/githugandroid/levels/MergeSquashLevel.kt
2026-06-26 18:10:48 -05:00

52 lines
2.5 KiB
Kotlin

package solutions.tretter.githugandroid
/**
* Port of the upstream ruby-githug `merge_squash` level.
*
* Setup documents the repository shape the learner explores. Evaluation is kept
* state-based whenever the exercise changes repository objects; answer-only
* levels intentionally validate the answer entered at the prompt.
*/
internal fun mergeSquashLevel(): Level = level(
id = "merge_squash",
title = "Merge Squash",
description = "Merge all commits from the long-feature-branch as a single commit.",
hints = listOf("Take a look at the `--squash` option of the merge command. Don't forget to commit the merge!"),
commandSuggestions = listOf("git merge --squash long-feature-branch", "git commit -m \"<message>\""),
setup = { RepoState(initialized = true, files = listOf(GitFile("file1", tracked = true)), branches = mapOf("master" to 2, "long-feature-branch" to 4)) },
nativeSetup = {
resetFiles()
write("file1")
addCommit("First commit", "file1")
checkoutNew("long-feature-branch")
write("file3", "some feature\n")
addCommit("Developing new features", "file3")
append("file3", "getting awesomer\n")
addCommit("Takes", "file3")
append("file3", "and awesomer!\n")
addCommit("Time", "file3")
checkout("master")
write("file2")
addCommit("Second commit", "file2")
true
},
validator = repoPredicate { repo ->
repo.headBranch == "master" &&
repo.commits.size == 3 &&
repo.commits.firstOrNull()?.parentCount == 1 &&
repo.files.any { it.name == "file3" && it.tracked && it.content == mergeSquashLevelFile3Content() }
},
testCases = listOf(
levelTestCase("squash merge then commit", "git merge --squash long-feature-branch", "git commit -m \"Merge long feature\""),
levelTestCase("squash merge with arbitrary message", "git merge --squash long-feature-branch", "git commit -m \"Any message works\""),
levelTestCase("squash no commit then commit", "git merge --squash --no-commit long-feature-branch", "git commit -m \"Finished feature branch\""),
),
negativeTestCases = listOf(
levelTestCase("squash merge without commit", "git merge --squash long-feature-branch"),
levelTestCase("regular merge is not a squash", "git merge --no-edit long-feature-branch"),
),
)
private fun mergeSquashLevelFile3Content(): String =
"some feature\ngetting awesomer\nand awesomer!\n"