fun reCommitChanges()

in bunch-cli/src/main/kotlin/org/jetbrains/bunches/git/git.kt [195:217]


fun reCommitChanges(
    repositoryPath: String, changes: List<FileAction>,
    commitInfo: CommitInfo, suffix: String? = null, prefix: String? = null
) {
    val repository = configureRepository(repositoryPath)
    val git = Git(repository)

    val addCommand = git.add()
    for (fileAction in changes) {
        val path = if (suffix != null) "${fileAction.newPath}.$suffix" else fileAction.newPath ?: continue
        val newFile = File(repositoryPath, path)
        newFile.parentFile.mkdirs()
        newFile.writeText(fileAction.content)
        addCommand.addFilepattern(path)
    }
    addCommand.call()

    git.commitEx()
        .setNoVerify(true)
        .setAuthor(commitInfo.author)
        .setMessage(generatePickedCommitMessage(commitInfo, suffix, prefix))
        .callEx()
}