fun commitChanges()

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


fun commitChanges(
    repositoryPath: String,
    changeFiles: Collection<FileChange>,
    title: String,
    noVerify: Boolean = false
) {
    val repoPath = File(repositoryPath)

    val repository = configureRepository(repositoryPath)
    val git = Git(repository)

    val addCommand = git.add()
    var hasAdd = false

    val rmCommand = git.rm().setCached(true)
    var hasRm = false

    for (changeFile in changeFiles) {
        val filePath = changeFile.file.relativeTo(repoPath).path.replace('\\', '/')
        when (changeFile.type) {
            ChangeType.ADD,
            ChangeType.MODIFY -> {
                hasAdd = true
                addCommand.addFilepattern(filePath)
            }
            ChangeType.REMOVE -> {
                hasRm = true
                rmCommand.addFilepattern(filePath)
            }
        }
    }

    if (hasAdd) {
        addCommand.call()
    }

    if (hasRm) {
        rmCommand.call()
    }

    git.commitEx()
        .setNoVerify(noVerify)
        .setMessage(title)
        .callEx()
}