Misc Changes
This commit is contained in:
@@ -740,7 +740,8 @@ class GitRepositoryRuntime private constructor(
|
||||
"fetch" -> {
|
||||
val remote = tokens.getOrNull(2)?.takeIf { !it.startsWith("-") } ?: "origin"
|
||||
inspectedRepo.copy(
|
||||
fetchedBranches = inspectedRepo.fetchedBranches + previousRepo.fetchedBranches + "$remote/master" + "$remote/feature_branch",
|
||||
fetchedBranches = inspectedRepo.fetchedBranches + previousRepo.fetchedBranches + "$remote/master" + "$remote/feature_branch" + "$remote/new_branch",
|
||||
maintenanceActions = inspectedRepo.maintenanceActions + previousRepo.maintenanceActions + "fetch",
|
||||
)
|
||||
}
|
||||
"pull" -> {
|
||||
@@ -788,7 +789,7 @@ class GitRepositoryRuntime private constructor(
|
||||
maintenanceActions = if ("--squash" in tokens) {
|
||||
inspectedRepo.maintenanceActions + previousRepo.maintenanceActions + "merge-squash"
|
||||
} else {
|
||||
inspectedRepo.maintenanceActions + previousRepo.maintenanceActions
|
||||
inspectedRepo.maintenanceActions + previousRepo.maintenanceActions + "merge"
|
||||
},
|
||||
)
|
||||
else -> inspectedRepo.copy(
|
||||
|
||||
@@ -62,7 +62,10 @@ object GitSandboxEngine {
|
||||
}
|
||||
parts.size >= 2 && parts[1] == "fetch" -> {
|
||||
val remote = parts.getOrNull(2)?.takeIf { !it.startsWith("-") } ?: "origin"
|
||||
repo.copy(fetchedBranches = repo.fetchedBranches + listOf("$remote/master", "$remote/feature_branch")) to emptyList()
|
||||
repo.copy(
|
||||
fetchedBranches = repo.fetchedBranches + listOf("$remote/master", "$remote/feature_branch", "$remote/new_branch"),
|
||||
maintenanceActions = repo.maintenanceActions + "fetch",
|
||||
) to emptyList()
|
||||
}
|
||||
parts.size >= 2 && parts[1] == "pull" -> {
|
||||
val remote = parts.getOrNull(2)?.takeIf { !it.startsWith("-") } ?: "origin"
|
||||
@@ -454,7 +457,7 @@ object GitSandboxEngine {
|
||||
}
|
||||
return repo.copy(
|
||||
files = files,
|
||||
maintenanceActions = if (squash) repo.maintenanceActions + "merge-squash" else repo.maintenanceActions,
|
||||
maintenanceActions = repo.maintenanceActions + if (squash) "merge-squash" else "merge",
|
||||
) to emptyList()
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,11 @@ internal fun fetchLevel(): Level = level(
|
||||
git("branch", "--set-upstream-to=origin/master", "master")
|
||||
true
|
||||
},
|
||||
validator = repoPredicate { repo -> "origin/new_branch" in repo.fetchedBranches && repo.headBranch == "master" },
|
||||
validator = repoPredicate { repo ->
|
||||
"fetch" in repo.maintenanceActions &&
|
||||
"origin/new_branch" in repo.fetchedBranches &&
|
||||
repo.headBranch == "master"
|
||||
},
|
||||
testCases = listOf(
|
||||
levelTestCase("fetch origin", "git fetch origin"),
|
||||
levelTestCase("fetch default", "git fetch"),
|
||||
|
||||
@@ -24,7 +24,11 @@ internal fun mergeLevel(): Level = level(
|
||||
checkout("master")
|
||||
true
|
||||
},
|
||||
validator = repoPredicate { repo -> repo.files.any { it.name == "file2" && it.tracked } },
|
||||
validator = repoPredicate { repo ->
|
||||
repo.headBranch == "master" &&
|
||||
"merge" in repo.maintenanceActions &&
|
||||
repo.files.any { it.name == "file2" && it.tracked }
|
||||
},
|
||||
testCases = listOf(
|
||||
levelTestCase("merge feature", "git merge feature"),
|
||||
),
|
||||
|
||||
@@ -13,7 +13,7 @@ internal fun statusLevel(): Level = level(
|
||||
description = "Among the files in this repository, which of them is untracked?",
|
||||
hints = listOf("You are looking for a command to identify the status of the repository."),
|
||||
commandSuggestions = listOf("git status"),
|
||||
setup = { RepoState(initialized = true, files = listOf(GitFile("database.yml"), GitFile("README", tracked = true)), branches = mapOf("master" to 0)) },
|
||||
setup = { RepoState(initialized = true, files = listOf(GitFile("database.yml")), branches = mapOf("master" to 0)) },
|
||||
validator = commandAnswer("database.yml"),
|
||||
testCases = listOf(
|
||||
levelTestCase("answer untracked file", "database.yml"),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package solutions.tretter.githugandroid
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
@@ -97,6 +98,30 @@ class LevelSolutionsTest {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun reportedRegressionCommandsDoNotSolveLevels() {
|
||||
val statusRepo = statusLevel().setup()
|
||||
assertEquals(listOf("database.yml"), statusRepo.files.map { it.name })
|
||||
|
||||
val gitBinary = testGitBinary()
|
||||
val runtimeRoot = testSandboxRoot().apply {
|
||||
deleteRecursively()
|
||||
mkdirs()
|
||||
}
|
||||
|
||||
val mergeExercise = mergeLevel()
|
||||
val mergeRuntime = GitRepositoryRuntime(runtimeRoot, gitBinary)
|
||||
val mergeRepo = mergeRuntime.prepareLevel(mergeExercise)
|
||||
val (switchedRepo, _) = mergeRuntime.execute(mergeExercise, mergeRepo, "git switch feature")
|
||||
assertFalse("Switching to feature must not solve the merge level.", mergeExercise.validator(switchedRepo, "git switch feature"))
|
||||
|
||||
val fetchExercise = fetchLevel()
|
||||
val fetchRuntime = GitRepositoryRuntime(runtimeRoot, gitBinary)
|
||||
val fetchRepo = fetchRuntime.prepareLevel(fetchExercise)
|
||||
val (pulledRepo, _) = fetchRuntime.execute(fetchExercise, fetchRepo, "git pull")
|
||||
assertFalse("Pulling must not solve the fetch level.", fetchExercise.validator(pulledRepo, "git pull"))
|
||||
}
|
||||
|
||||
private companion object {
|
||||
fun writeEvidenceLog(content: String) {
|
||||
val repoRoot = File(System.getProperty("user.dir") ?: ".")
|
||||
|
||||
Reference in New Issue
Block a user