Files
Githug-Android/app/src/main/java/solutions/tretter/githugandroid/levels/SquashLevel.kt
Joe Tretter 781b5090f7 Fix Git editor reword workflow and UI coverage
- show Git editor file paths instead of the submitted git command
- surface follow-up commit message editors during interactive rebase reword
- add rename-commit UI tests for editor and amend-message solution paths
- add broader embedded level solution scenarios for alternate Git workflows
2026-06-26 11:23:16 -05:00

53 lines
2.3 KiB
Kotlin

package solutions.tretter.githugandroid
/**
* Port of the upstream ruby-githug `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 squashLevel(): Level = level(
id = "squash",
title = "Squash",
description = "You have committed several times but would like all those changes to be one commit.",
hints = listOf("Take a look at the `-i` flag of the rebase command."),
commandSuggestions = listOf("git rebase -i HEAD~4"),
setup = { RepoState(initialized = true, commits = listOf(CommitNode("1", "Initial Commit"), CommitNode("2", "Adding README"), CommitNode("3", "Updating README (squash this commit into Adding README)"), CommitNode("4", "Updating README (squash this commit into Adding README)"), CommitNode("5", "Updating README (squash this commit into Adding README)")), branches = mapOf("master" to 5)) },
nativeSetup = {
resetFiles()
write(".hidden")
addCommit("Initial Commit", ".hidden")
write("README")
addCommit("Adding README", "README")
write("README", "hey there")
addCommit("Updating README (squash this commit into Adding README)", "README")
append("README", "\nAdding some more text")
addCommit("Updating README (squash this commit into Adding README)", "README")
append("README", "\neven more text")
addCommit("Updating README (squash this commit into Adding README)", "README")
true
},
validator = repoPredicate { repo -> repo.commits.size == 2 },
testCases = listOf(
levelTestCase(
"interactive squash",
"GIT_SEQUENCE_EDITOR=\"sed -i '2,\$s/^pick /squash /'\" GIT_EDITOR=true git rebase -i HEAD~4",
),
levelTestCase(
"soft reset and recommit",
"git reset --soft HEAD~4",
"git commit -m \"New commit message\"",
),
levelTestCase(
"mixed reset add and recommit",
"git reset HEAD~4",
"git add README",
"git commit -m \"New commit message\"",
),
),
negativeTestCases = listOf(
levelTestCase("reset without replacement commit", "git reset --soft HEAD~4"),
),
)