~jan0sch/smederee
Showing details for patch ed6c428980a41666a590d9043dd2cfbd883c8f5c.
diff -rN -u old-smederee/modules/darcs/src/main/scala/de/smederee/darcs/DarcsCommands.scala new-smederee/modules/darcs/src/main/scala/de/smederee/darcs/DarcsCommands.scala --- old-smederee/modules/darcs/src/main/scala/de/smederee/darcs/DarcsCommands.scala 2025-06-20 20:15:58.622659196 +0000 +++ new-smederee/modules/darcs/src/main/scala/de/smederee/darcs/DarcsCommands.scala 2025-06-20 20:15:58.622659196 +0000 @@ -241,6 +241,28 @@ } yield DarcsCommandOutput(process.exitCode, Chain(process.out.text()), Chain(process.err.text())) } + /** Run the darcs repair command on the given repository and return the output. The main usage should be using the + * `--dry-run` option to not actually perform any actions but to check if the repository is corrupted. + * + * @param basePath + * The base path under which the repository is located. + * @param repositoryName + * The name of the repository. + * @param options + * Additional options for the log command. + * @return + * The output of the darcs command. + */ + def repair(basePath: Path)(repositoryName: String)(options: Chain[String]): F[DarcsCommandOutput] = { + log.trace(s"Execute $darcsBinary repair in $basePath/$repositoryName with $options") + val directory = Paths.get(basePath.toString, repositoryName) + val darcsOptions = List("repair") ::: options.toList + val externalCommand = os.proc(darcsBinary.toString, darcsOptions) + for { + process <- Sync[F].delay(externalCommand.call(cwd = os.Path(directory), check = false)) + } yield DarcsCommandOutput(process.exitCode, Chain(process.out.text()), Chain(process.err.text())) + } + /** Run the darcs show dependencies command on the given repository and return the output. * * @param basePath diff -rN -u old-smederee/modules/darcs/src/test/scala/de/smederee/darcs/DarcsCommandsTest.scala new-smederee/modules/darcs/src/test/scala/de/smederee/darcs/DarcsCommandsTest.scala --- old-smederee/modules/darcs/src/test/scala/de/smederee/darcs/DarcsCommandsTest.scala 2025-06-20 20:15:58.622659196 +0000 +++ new-smederee/modules/darcs/src/test/scala/de/smederee/darcs/DarcsCommandsTest.scala 2025-06-20 20:15:58.622659196 +0000 @@ -119,4 +119,27 @@ assert(output.stderr.nonEmpty) } } + + tempWorkingDirectory.test("darcs repair must return 0 on a consistent repository") { workingDirectory => + val cmd = new DarcsCommands[IO](darcsBinary) + val repo = "test-apply" + val expectedDirectory = workingDirectory.resolve(repo) + val testPatch = Paths.get(getClass().getClassLoader().getResource("test-patch.dpatch").toURI()) + val createRepository = cmd.initialize(workingDirectory)(repo)(Chain.empty) + val test = for { + init <- createRepository + patch <- cmd.applyPatch(workingDirectory)(repo)(testPatch)(Chain.empty) + repair <- cmd.repair(workingDirectory)(repo)(Chain("--dry-run")) + } yield (init, patch, repair) + test.map { output => + val (init, patch, repair) = output + assert(init.exitValue === 0, "darcs init did not finish with exit code 0!") + assert(patch.exitValue === 0, "darcs apply did not finish with exit code 0!") + assert( + Files.exists(expectedDirectory.resolve("README.md")), + "Expected file README.md missing after applying the patch!" + ) + assert(repair.exitValue === 0, "darcs repair --dry-run dit not finish with exit code 0!") + } + } }