remove vcs connectors in favor of externally fed logs

Sat, 22 Jul 2023 13:04:12 +0200

author
Mike Becker <universe@uap-core.de>
date
Sat, 22 Jul 2023 13:04:12 +0200
changeset 282
c112fad21bf6
parent 281
c15b9555ecf3
child 283
ea6181255423

remove vcs connectors in favor of externally fed logs

relates to #276

src/main/kotlin/de/uapcore/lightpit/types/CommitRef.kt file | annotate | diff | comparison | revisions
src/main/kotlin/de/uapcore/lightpit/vcs/CommitRef.kt file | annotate | diff | comparison | revisions
src/main/kotlin/de/uapcore/lightpit/vcs/HgConnector.kt file | annotate | diff | comparison | revisions
src/main/kotlin/de/uapcore/lightpit/vcs/VcsConnector.kt file | annotate | diff | comparison | revisions
src/main/kotlin/de/uapcore/lightpit/vcs/VcsConnectorResult.kt file | annotate | diff | comparison | revisions
src/test/kotlin/de/uapcore/lightpit/types/CommitRefTest.kt file | annotate | diff | comparison | revisions
src/test/kotlin/de/uapcore/lightpit/vcs/HgConnectorTest.kt file | annotate | diff | comparison | revisions
src/test/resources/test-repo/hg/00changelog.i file | annotate | diff | comparison | revisions
src/test/resources/test-repo/hg/cache/branch2-served file | annotate | diff | comparison | revisions
src/test/resources/test-repo/hg/cache/rbc-names-v1 file | annotate | diff | comparison | revisions
src/test/resources/test-repo/hg/cache/rbc-revs-v1 file | annotate | diff | comparison | revisions
src/test/resources/test-repo/hg/cache/tags2-visible file | annotate | diff | comparison | revisions
src/test/resources/test-repo/hg/dirstate file | annotate | diff | comparison | revisions
src/test/resources/test-repo/hg/last-message.txt file | annotate | diff | comparison | revisions
src/test/resources/test-repo/hg/requires file | annotate | diff | comparison | revisions
src/test/resources/test-repo/hg/store/00changelog.i file | annotate | diff | comparison | revisions
src/test/resources/test-repo/hg/store/00manifest.i file | annotate | diff | comparison | revisions
src/test/resources/test-repo/hg/store/data/another-file.i file | annotate | diff | comparison | revisions
src/test/resources/test-repo/hg/store/data/testfile.i file | annotate | diff | comparison | revisions
src/test/resources/test-repo/hg/store/fncache file | annotate | diff | comparison | revisions
src/test/resources/test-repo/hg/store/phaseroots file | annotate | diff | comparison | revisions
src/test/resources/test-repo/hg/store/requires file | annotate | diff | comparison | revisions
src/test/resources/test-repo/hg/store/undo file | annotate | diff | comparison | revisions
src/test/resources/test-repo/hg/store/undo.backup.fncache file | annotate | diff | comparison | revisions
src/test/resources/test-repo/hg/store/undo.backupfiles file | annotate | diff | comparison | revisions
src/test/resources/test-repo/hg/store/undo.phaseroots file | annotate | diff | comparison | revisions
src/test/resources/test-repo/hg/undo.backup.dirstate file | annotate | diff | comparison | revisions
src/test/resources/test-repo/hg/undo.bookmarks file | annotate | diff | comparison | revisions
src/test/resources/test-repo/hg/undo.branch file | annotate | diff | comparison | revisions
src/test/resources/test-repo/hg/undo.desc file | annotate | diff | comparison | revisions
src/test/resources/test-repo/hg/undo.dirstate file | annotate | diff | comparison | revisions
src/test/resources/test-repo/hg/wcache/checkisexec file | annotate | diff | comparison | revisions
src/test/resources/test-repo/hg/wcache/checklink file | annotate | diff | comparison | revisions
src/test/resources/test-repo/hg/wcache/checklink-target file | annotate | diff | comparison | revisions
src/test/resources/test-repo/hg/wcache/checknoexec file | annotate | diff | comparison | revisions
src/test/resources/test-repo/hg/wcache/manifestfulltextcache file | annotate | diff | comparison | revisions
src/test/resources/test-repo/testfile file | annotate | diff | comparison | revisions
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/main/kotlin/de/uapcore/lightpit/types/CommitRef.kt	Sat Jul 22 13:04:12 2023 +0200
     1.3 @@ -0,0 +1,64 @@
     1.4 +/*
     1.5 + * Copyright 2023 Mike Becker. All rights reserved.
     1.6 + *
     1.7 + * Redistribution and use in source and binary forms, with or without
     1.8 + * modification, are permitted provided that the following conditions are met:
     1.9 + *
    1.10 + * 1. Redistributions of source code must retain the above copyright
    1.11 + * notice, this list of conditions and the following disclaimer.
    1.12 + *
    1.13 + * 2. Redistributions in binary form must reproduce the above copyright
    1.14 + * notice, this list of conditions and the following disclaimer in the
    1.15 + * documentation and/or other materials provided with the distribution.
    1.16 + *
    1.17 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    1.18 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    1.19 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    1.20 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
    1.21 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    1.22 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    1.23 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
    1.24 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
    1.25 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    1.26 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.27 + *
    1.28 + */
    1.29 +
    1.30 +package de.uapcore.lightpit.types
    1.31 +
    1.32 +data class CommitRef(val hash: String, val issueId: Int, val message: String)
    1.33 +
    1.34 +/**
    1.35 + * Takes a [commitLog] in format `::lpitref::{node}:{desc}` and parses commit references.
    1.36 + * Supported references are (in this example, 47 is the issue ID):
    1.37 + *  - fixes #47
    1.38 + *  - fix #47
    1.39 + *  - closes #47
    1.40 + *  - close #47
    1.41 + *  - relates to #47
    1.42 + */
    1.43 +fun parseCommitRefs(commitLog: String): List<CommitRef> = buildList {
    1.44 +    val marker = "::lpitref:"
    1.45 +    var currentHash = ""
    1.46 +    var currentDesc = ""
    1.47 +    for (line in commitLog.split("\n")) {
    1.48 +        // see if current line contains a new log entry
    1.49 +        if (line.startsWith(marker)) {
    1.50 +            val head = line.substring(marker.length).split(':', limit = 2)
    1.51 +            currentHash = head[0]
    1.52 +            currentDesc = head[1]
    1.53 +        }
    1.54 +
    1.55 +        // skip possible preamble output
    1.56 +        if (currentHash.isEmpty()) continue
    1.57 +
    1.58 +        // scan the lines for commit references
    1.59 +        Regex("""(?:relates to|fix(?:es)?|close(?:es)?) #(\d+)""")
    1.60 +            .findAll(line)
    1.61 +            .map { it.groupValues[1] }
    1.62 +            .map { it.toIntOrNull() }
    1.63 +            .filterNotNull()
    1.64 +            .forEach { commitId -> add(CommitRef(currentHash, commitId, currentDesc)) }
    1.65 +    }
    1.66 +}
    1.67 +
     2.1 --- a/src/main/kotlin/de/uapcore/lightpit/vcs/CommitRef.kt	Sat Jul 22 11:32:27 2023 +0200
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,3 +0,0 @@
     2.4 -package de.uapcore.lightpit.vcs
     2.5 -
     2.6 -data class CommitRef(val hash: String, val issueId: Int, val message: String)
     3.1 --- a/src/main/kotlin/de/uapcore/lightpit/vcs/HgConnector.kt	Sat Jul 22 11:32:27 2023 +0200
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,82 +0,0 @@
     3.4 -/*
     3.5 - * Copyright 2023 Mike Becker. All rights reserved.
     3.6 - *
     3.7 - * Redistribution and use in source and binary forms, with or without
     3.8 - * modification, are permitted provided that the following conditions are met:
     3.9 - *
    3.10 - * 1. Redistributions of source code must retain the above copyright
    3.11 - * notice, this list of conditions and the following disclaimer.
    3.12 - *
    3.13 - * 2. Redistributions in binary form must reproduce the above copyright
    3.14 - * notice, this list of conditions and the following disclaimer in the
    3.15 - * documentation and/or other materials provided with the distribution.
    3.16 - *
    3.17 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    3.18 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    3.19 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    3.20 - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
    3.21 - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    3.22 - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    3.23 - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
    3.24 - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
    3.25 - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    3.26 - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    3.27 - *
    3.28 - */
    3.29 -
    3.30 -package de.uapcore.lightpit.vcs
    3.31 -
    3.32 -import java.nio.file.Files
    3.33 -import kotlin.io.path.ExperimentalPathApi
    3.34 -import kotlin.io.path.deleteRecursively
    3.35 -
    3.36 -/**
    3.37 - * A connector for Mercurial repositories.
    3.38 - *
    3.39 - * @param path the path to the Mercurial binary
    3.40 - */
    3.41 -class HgConnector(path: String) : VcsConnector(path) {
    3.42 -
    3.43 -    /**
    3.44 -     * Checks, if the specified binary is available and executable.
    3.45 -     */
    3.46 -    fun checkAvailability(): Boolean {
    3.47 -        return when (val versionInfo = invokeCommand("--version")) {
    3.48 -            is VcsConnectorResult.Success -> versionInfo.content.contains("Mercurial")
    3.49 -            else -> false
    3.50 -        }
    3.51 -    }
    3.52 -
    3.53 -    /**
    3.54 -     * Reads the commit log and parses every reference to an issue.
    3.55 -     *
    3.56 -     * The [pathOrUrl] must be a valid path or URL recognized by the VCS binary.
    3.57 -     * Currently, no authentication is supported and the repository must therefore be publicly readable.
    3.58 -     */
    3.59 -    @OptIn(ExperimentalPathApi::class)
    3.60 -    fun readCommitLog(pathOrUrl: String): VcsConnectorResult<List<CommitRef>> {
    3.61 -        val tmpDir = try {
    3.62 -            Files.createTempDirectory("lightpit-vcs-")
    3.63 -        } catch (e: Throwable) {
    3.64 -            return VcsConnectorResult.Error("Creating temporary directory for VCS connection failed: " + e.message)
    3.65 -        }
    3.66 -        val init = invokeCommand("init", workingDir = tmpDir)
    3.67 -        if (init is VcsConnectorResult.Error) {
    3.68 -            return init
    3.69 -        }
    3.70 -
    3.71 -        val commitLogContent = when (val result = invokeCommand(
    3.72 -            "incoming", pathOrUrl, "-n", "--template", "::lpitref::{node}:{desc}\\n",
    3.73 -            workingDir = tmpDir,
    3.74 -            timeout = 60
    3.75 -        )) {
    3.76 -            is VcsConnectorResult.Error -> return result
    3.77 -            is VcsConnectorResult.Success -> result.content
    3.78 -        }
    3.79 -
    3.80 -        val commitRefs = parseCommitRefs(commitLogContent)
    3.81 -
    3.82 -        tmpDir.deleteRecursively()
    3.83 -        return VcsConnectorResult.Success(commitRefs)
    3.84 -    }
    3.85 -}
    3.86 \ No newline at end of file
     4.1 --- a/src/main/kotlin/de/uapcore/lightpit/vcs/VcsConnector.kt	Sat Jul 22 11:32:27 2023 +0200
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,67 +0,0 @@
     4.4 -package de.uapcore.lightpit.vcs
     4.5 -
     4.6 -import java.nio.file.Path
     4.7 -import java.util.concurrent.TimeUnit
     4.8 -
     4.9 -abstract class VcsConnector(protected val path: String) {
    4.10 -    /**
    4.11 -     * Invokes the VCS binary with the given [args] and returns the output on stdout.
    4.12 -     */
    4.13 -    protected fun invokeCommand(
    4.14 -        vararg args: String,
    4.15 -        workingDir: Path = Path.of("."),
    4.16 -        timeout: Long = 30L
    4.17 -    ): VcsConnectorResult<String> {
    4.18 -        return try {
    4.19 -            val command = mutableListOf(path)
    4.20 -            command.addAll(args)
    4.21 -            val process = ProcessBuilder(command).directory(workingDir.toFile()).start()
    4.22 -            val stdout = String(process.inputStream.readAllBytes(), Charsets.UTF_8)
    4.23 -            if (process.waitFor(timeout, TimeUnit.SECONDS)) {
    4.24 -                if (process.exitValue() == 0) {
    4.25 -                    VcsConnectorResult.Success(stdout)
    4.26 -                } else {
    4.27 -                    VcsConnectorResult.Error("VCS process did not return successfully.")
    4.28 -                }
    4.29 -            } else {
    4.30 -                VcsConnectorResult.Error("VCS process did not return in time.")
    4.31 -            }
    4.32 -        } catch (e: Throwable) {
    4.33 -            VcsConnectorResult.Error("Error during process invocation: "+e.message)
    4.34 -        }
    4.35 -    }
    4.36 -
    4.37 -    /**
    4.38 -     * Takes a [commitLog] in format `::lpitref::{node}:{desc}` and parses commit references.
    4.39 -     * Supported references are (in this example, 47 is the issue ID):
    4.40 -     *  - fixes #47
    4.41 -     *  - fix #47
    4.42 -     *  - closes #47
    4.43 -     *  - close #47
    4.44 -     *  - relates to #47
    4.45 -     */
    4.46 -    protected fun parseCommitRefs(commitLog: String): List<CommitRef> = buildList {
    4.47 -        val marker = "::lpitref::"
    4.48 -        var currentHash = ""
    4.49 -        var currentDesc = ""
    4.50 -        for (line in commitLog.split("\n")) {
    4.51 -            // see if current line contains a new log entry
    4.52 -            if (line.startsWith(marker)) {
    4.53 -                val head = line.substring(marker.length).split(':', limit = 2)
    4.54 -                currentHash = head[0]
    4.55 -                currentDesc = head[1]
    4.56 -            }
    4.57 -
    4.58 -            // skip possible preamble output
    4.59 -            if (currentHash.isEmpty()) continue
    4.60 -
    4.61 -            // scan the lines for commit references
    4.62 -            Regex("""(?:relates to|fix(?:es)?|close(?:es)?) #(\d+)""")
    4.63 -                .findAll(line)
    4.64 -                .map { it.groupValues[1] }
    4.65 -                .map { it.toIntOrNull() }
    4.66 -                .filterNotNull()
    4.67 -                .forEach { commitId -> add(CommitRef(currentHash, commitId, currentDesc)) }
    4.68 -        }
    4.69 -    }
    4.70 -}
    4.71 \ No newline at end of file
     5.1 --- a/src/main/kotlin/de/uapcore/lightpit/vcs/VcsConnectorResult.kt	Sat Jul 22 11:32:27 2023 +0200
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,6 +0,0 @@
     5.4 -package de.uapcore.lightpit.vcs
     5.5 -
     5.6 -sealed class VcsConnectorResult<out T> {
     5.7 -    data class Success<T>(val content: T) : VcsConnectorResult<T>()
     5.8 -    data class Error(val message: String) : VcsConnectorResult<Nothing>()
     5.9 -}
    5.10 \ No newline at end of file
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/test/kotlin/de/uapcore/lightpit/types/CommitRefTest.kt	Sat Jul 22 13:04:12 2023 +0200
     6.3 @@ -0,0 +1,63 @@
     6.4 +/*
     6.5 + * Copyright 2023 Mike Becker. All rights reserved.
     6.6 + *
     6.7 + * Redistribution and use in source and binary forms, with or without
     6.8 + * modification, are permitted provided that the following conditions are met:
     6.9 + *
    6.10 + * 1. Redistributions of source code must retain the above copyright
    6.11 + * notice, this list of conditions and the following disclaimer.
    6.12 + *
    6.13 + * 2. Redistributions in binary form must reproduce the above copyright
    6.14 + * notice, this list of conditions and the following disclaimer in the
    6.15 + * documentation and/or other materials provided with the distribution.
    6.16 + *
    6.17 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    6.18 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    6.19 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    6.20 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
    6.21 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    6.22 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    6.23 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
    6.24 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
    6.25 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    6.26 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    6.27 + *
    6.28 + */
    6.29 +
    6.30 +package de.uapcore.lightpit.types
    6.31 +
    6.32 +import kotlin.test.Test
    6.33 +import kotlin.test.assertContentEquals
    6.34 +
    6.35 +class CommitRefTest {
    6.36 +
    6.37 +    @Test
    6.38 +    fun readCommitLog() {
    6.39 +        assertContentEquals(
    6.40 +            listOf(
    6.41 +                CommitRef("cf9f5982ddeb28c7f695dc547fe73abf5460016f", 50, "here we fix #50"),
    6.42 +                CommitRef("cf9f5982ddeb28c7f695dc547fe73abf5460016f", 30, "here we fix #50"),
    6.43 +                CommitRef(
    6.44 +                    "ed7134e5f4ce278c4f62798fb9f96129be2b132b",
    6.45 +                    1337,
    6.46 +                    "commit with a #non-ref, relates to #wrong ref but still fixes #1337"
    6.47 +                ),
    6.48 +                CommitRef("74d770da3c80c0c3fc1fb7e44fb710d665127dfe", 47, "a change with commitref in body"),
    6.49 +                CommitRef("9a14e5628bdf2d578f3385d78022ddcaf23d1abb", 47, "add test file - relates to #47")
    6.50 +            ),
    6.51 +            parseCommitRefs(
    6.52 +                """::lpitref:cf9f5982ddeb28c7f695dc547fe73abf5460016f:here we fix #50
    6.53 +
    6.54 +and close #30
    6.55 +::lpitref:ed7134e5f4ce278c4f62798fb9f96129be2b132b:commit with a #non-ref, relates to #wrong ref but still fixes #1337
    6.56 +::lpitref:74d770da3c80c0c3fc1fb7e44fb710d665127dfe:a change with commitref in body
    6.57 +
    6.58 +some more details
    6.59 +fixes #47
    6.60 +::lpitref:d533c717dfecb8e4b993ca6c8760f1493bc834b6:no commitref
    6.61 +::lpitref:9a14e5628bdf2d578f3385d78022ddcaf23d1abb:add test file - relates to #47
    6.62 +"""
    6.63 +            )
    6.64 +        )
    6.65 +    }
    6.66 +}
    6.67 \ No newline at end of file
     7.1 --- a/src/test/kotlin/de/uapcore/lightpit/vcs/HgConnectorTest.kt	Sat Jul 22 11:32:27 2023 +0200
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,87 +0,0 @@
     7.4 -/*
     7.5 - * Copyright 2023 Mike Becker. All rights reserved.
     7.6 - *
     7.7 - * Redistribution and use in source and binary forms, with or without
     7.8 - * modification, are permitted provided that the following conditions are met:
     7.9 - *
    7.10 - * 1. Redistributions of source code must retain the above copyright
    7.11 - * notice, this list of conditions and the following disclaimer.
    7.12 - *
    7.13 - * 2. Redistributions in binary form must reproduce the above copyright
    7.14 - * notice, this list of conditions and the following disclaimer in the
    7.15 - * documentation and/or other materials provided with the distribution.
    7.16 - *
    7.17 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    7.18 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    7.19 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    7.20 - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
    7.21 - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    7.22 - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    7.23 - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
    7.24 - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
    7.25 - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    7.26 - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    7.27 - *
    7.28 - */
    7.29 -
    7.30 -package de.uapcore.lightpit.vcs
    7.31 -
    7.32 -import kotlin.io.path.Path
    7.33 -import kotlin.io.path.absolutePathString
    7.34 -import kotlin.io.path.exists
    7.35 -import kotlin.io.path.moveTo
    7.36 -import kotlin.test.*
    7.37 -
    7.38 -class HgConnectorTest {
    7.39 -
    7.40 -    private val testee = HgConnector("/usr/bin/hg")
    7.41 -    private val testRepoPath = Path("src/test/resources/test-repo")
    7.42 -
    7.43 -    @BeforeTest
    7.44 -    fun prepareTestRepo() {
    7.45 -        assertTrue(testRepoPath.exists(), "Test must be run from the project root.")
    7.46 -        val hg = testRepoPath.resolve("hg")
    7.47 -        val dothg = testRepoPath.resolve(".hg")
    7.48 -        assertTrue(hg.exists(), "hg dir not found, maybe a previous execution did not terminated cleanly.")
    7.49 -        assertFalse(dothg.exists(), ".hg dir found, maybe a previous execution did not terminated cleanly.")
    7.50 -        hg.moveTo(dothg)
    7.51 -    }
    7.52 -
    7.53 -    @AfterTest
    7.54 -    fun cleanup() {
    7.55 -        val hg = testRepoPath.resolve("hg")
    7.56 -        val dothg = testRepoPath.resolve(".hg")
    7.57 -        dothg.moveTo(hg)
    7.58 -    }
    7.59 -
    7.60 -    @Test
    7.61 -    fun checkAvailability() {
    7.62 -        assertTrue(testee.checkAvailability())
    7.63 -    }
    7.64 -
    7.65 -    @Test
    7.66 -    fun checkAvailabilityFalse() {
    7.67 -        assertFalse(HgConnector("/bin/false").checkAvailability())
    7.68 -    }
    7.69 -
    7.70 -    @Test
    7.71 -    fun readCommitLog() {
    7.72 -        val result = testee.readCommitLog(testRepoPath.absolutePathString())
    7.73 -        assertTrue(result is VcsConnectorResult.Success)
    7.74 -
    7.75 -        assertContentEquals(
    7.76 -            listOf(
    7.77 -                CommitRef("cf9f5982ddeb28c7f695dc547fe73abf5460016f", 50, "here we fix #50"),
    7.78 -                CommitRef("cf9f5982ddeb28c7f695dc547fe73abf5460016f", 30, "here we fix #50"),
    7.79 -                CommitRef(
    7.80 -                    "ed7134e5f4ce278c4f62798fb9f96129be2b132b",
    7.81 -                    1337,
    7.82 -                    "commit with a #non-ref, relates to #wrong ref but still fixes #1337"
    7.83 -                ),
    7.84 -                CommitRef("74d770da3c80c0c3fc1fb7e44fb710d665127dfe", 47, "a change with commitref in body"),
    7.85 -                CommitRef("9a14e5628bdf2d578f3385d78022ddcaf23d1abb", 47, "add test file - relates to #47")
    7.86 -            ),
    7.87 -            result.content
    7.88 -        )
    7.89 -    }
    7.90 -}
    7.91 \ No newline at end of file
     8.1 Binary file src/test/resources/test-repo/hg/00changelog.i has changed
     9.1 --- a/src/test/resources/test-repo/hg/cache/branch2-served	Sat Jul 22 11:32:27 2023 +0200
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,2 +0,0 @@
     9.4 -cf9f5982ddeb28c7f695dc547fe73abf5460016f 4
     9.5 -cf9f5982ddeb28c7f695dc547fe73abf5460016f o default
    10.1 --- a/src/test/resources/test-repo/hg/cache/rbc-names-v1	Sat Jul 22 11:32:27 2023 +0200
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,1 +0,0 @@
    10.4 -default
    10.5 \ No newline at end of file
    11.1 Binary file src/test/resources/test-repo/hg/cache/rbc-revs-v1 has changed
    12.1 --- a/src/test/resources/test-repo/hg/cache/tags2-visible	Sat Jul 22 11:32:27 2023 +0200
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,1 +0,0 @@
    12.4 -4 cf9f5982ddeb28c7f695dc547fe73abf5460016f
    13.1 Binary file src/test/resources/test-repo/hg/dirstate has changed
    14.1 --- a/src/test/resources/test-repo/hg/last-message.txt	Sat Jul 22 11:32:27 2023 +0200
    14.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.3 @@ -1,4 +0,0 @@
    14.4 -here we fix #50
    14.5 -
    14.6 -and close #30
    14.7 -
    15.1 --- a/src/test/resources/test-repo/hg/requires	Sat Jul 22 11:32:27 2023 +0200
    15.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.3 @@ -1,1 +0,0 @@
    15.4 -share-safe
    16.1 Binary file src/test/resources/test-repo/hg/store/00changelog.i has changed
    17.1 Binary file src/test/resources/test-repo/hg/store/00manifest.i has changed
    18.1 Binary file src/test/resources/test-repo/hg/store/data/another-file.i has changed
    19.1 Binary file src/test/resources/test-repo/hg/store/data/testfile.i has changed
    20.1 --- a/src/test/resources/test-repo/hg/store/fncache	Sat Jul 22 11:32:27 2023 +0200
    20.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.3 @@ -1,2 +0,0 @@
    20.4 -data/testfile.i
    20.5 -data/another-file.i
    21.1 --- a/src/test/resources/test-repo/hg/store/phaseroots	Sat Jul 22 11:32:27 2023 +0200
    21.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.3 @@ -1,1 +0,0 @@
    21.4 -1 9a14e5628bdf2d578f3385d78022ddcaf23d1abb
    22.1 --- a/src/test/resources/test-repo/hg/store/requires	Sat Jul 22 11:32:27 2023 +0200
    22.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.3 @@ -1,7 +0,0 @@
    22.4 -dotencode
    22.5 -fncache
    22.6 -generaldelta
    22.7 -revlog-compression-zstd
    22.8 -revlogv1
    22.9 -sparserevlog
   22.10 -store
    23.1 Binary file src/test/resources/test-repo/hg/store/undo has changed
    24.1 --- a/src/test/resources/test-repo/hg/store/undo.backup.fncache	Sat Jul 22 11:32:27 2023 +0200
    24.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.3 @@ -1,1 +0,0 @@
    24.4 -data/testfile.i
    25.1 Binary file src/test/resources/test-repo/hg/store/undo.backupfiles has changed
    26.1 --- a/src/test/resources/test-repo/hg/store/undo.phaseroots	Sat Jul 22 11:32:27 2023 +0200
    26.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.3 @@ -1,1 +0,0 @@
    26.4 -1 9a14e5628bdf2d578f3385d78022ddcaf23d1abb
    27.1 Binary file src/test/resources/test-repo/hg/undo.backup.dirstate has changed
    28.1 --- a/src/test/resources/test-repo/hg/undo.branch	Sat Jul 22 11:32:27 2023 +0200
    28.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.3 @@ -1,1 +0,0 @@
    28.4 -default
    28.5 \ No newline at end of file
    29.1 --- a/src/test/resources/test-repo/hg/undo.desc	Sat Jul 22 11:32:27 2023 +0200
    29.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.3 @@ -1,2 +0,0 @@
    29.4 -4
    29.5 -commit
    30.1 Binary file src/test/resources/test-repo/hg/undo.dirstate has changed
    31.1 --- a/src/test/resources/test-repo/hg/wcache/checklink	Sat Jul 22 11:32:27 2023 +0200
    31.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    31.3 @@ -1,1 +0,0 @@
    31.4 -checklink-target
    31.5 \ No newline at end of file
    32.1 Binary file src/test/resources/test-repo/hg/wcache/manifestfulltextcache has changed
    33.1 --- a/src/test/resources/test-repo/testfile	Sat Jul 22 11:32:27 2023 +0200
    33.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    33.3 @@ -1,1 +0,0 @@
    33.4 -Just a test file.

mercurial