package solutions.tretter.githugandroid /** * Port of the upstream ruby-githug `checkout_file` 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 checkoutFileLevel(): Level = level( id = "checkout_file", title = "Checkout File", description = "A file has been modified, but you don't want to keep the modification. Checkout the `config.rb` file from the last commit.", hints = listOf("You will need to do some research on the checkout command for this one."), commandSuggestions = listOf("git checkout -- config.rb"), setup = { RepoState(initialized = true, files = listOf(GitFile("config.rb", "This is the initial config file\nThese are changes you don't want to keep!", tracked = true)), commits = listOf(CommitNode("0000001", "Added initial config file")), branches = mapOf("master" to 1)) }, nativeSetup = { resetFiles() write("config.rb", "This is the initial config file") addCommit("Added initial config file", "config.rb") append("config.rb", "\nThese are changes you don't want to keep!") true }, validator = repoPredicate { repo -> repo.files.find { it.name == "config.rb" }?.content == "This is the initial config file" }, testCases = listOf( levelTestCase("checkout file from head", "git checkout -- config.rb"), levelTestCase("restore file from index", "git restore config.rb"), levelTestCase("checkout file from explicit head", "git checkout HEAD -- config.rb"), ), )