44 lines
2.0 KiB
Kotlin
44 lines
2.0 KiB
Kotlin
package solutions.tretter.githugandroid
|
|
|
|
/**
|
|
* Port of the upstream ruby-githug `revert` 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 revertLevel(): Level = level(
|
|
id = "revert",
|
|
title = "Revert",
|
|
description = "You have committed several times but want to undo the middle commit. All commits have been pushed, so you can't change existing history.",
|
|
hints = listOf("Try the revert command."),
|
|
commandSuggestions = listOf("git revert HEAD~1"),
|
|
setup = { RepoState(initialized = true, commits = listOf(CommitNode("1", "First commit"), CommitNode("2", "Bad commit"), CommitNode("3", "Second commit")), branches = mapOf("master" to 3), pushedBranches = setOf("origin/master")) },
|
|
nativeSetup = {
|
|
resetFiles()
|
|
write("file1")
|
|
addCommit("First commit", "file1")
|
|
write("file3")
|
|
addCommit("Bad commit", "file3")
|
|
write("file2")
|
|
addCommit("Second commit", "file2")
|
|
true
|
|
},
|
|
validator = repoPredicate { repo ->
|
|
repo.headBranch == "master" &&
|
|
repo.commits.size >= 4 &&
|
|
repo.commits.firstOrNull()?.parentCount == 1 &&
|
|
repo.files.none { it.name == "file3" && !it.deleted } &&
|
|
repo.commits.map { it.message }.containsAll(listOf("First commit", "Bad commit", "Second commit"))
|
|
},
|
|
testCases = listOf(
|
|
levelTestCase("revert middle commit", "git revert HEAD~1"),
|
|
levelTestCase("revert middle commit without editor", "git revert --no-edit HEAD~1"),
|
|
levelTestCase("revert caret commit", "git revert HEAD^"),
|
|
levelTestCase("revert without commit then arbitrary message", "git revert -n HEAD~1", "git commit -m \"Undo unwanted file\""),
|
|
),
|
|
negativeTestCases = listOf(
|
|
levelTestCase("revert without replacement commit", "git revert -n HEAD~1"),
|
|
),
|
|
)
|