Skip to content

AddCommand.addFilePatterns #247

@nikclayton

Description

@nikclayton

Description

I'd like an AddCommand.addFilePatterns method that takes a Collection<String>, and calls AddCommand.addFilePattern on each member of the collection.

Motivation

I have (Kotlin) code using JGit to add files. The call site looks like this:

git.add()
    .setUpdate(false)
    .addFilepattern("CHANGELOG.md")
    .addFilepattern("app/build.gradle.kts")
    .call()

Now I need to amend this to add multiple files, where the list of files to add is returned by another function. Currently this is awkward, and becomes something like:

val patternsToAdd = myfunc()

val addCommand = git.add()
    .setUpdate(false)
    .addFilepattern("CHANGELOG.md")
    .addFilepattern("app/build.gradle.kts")

patternsToAdd.forEach { addCommand.addFilePattern(it) }

addCommand.call()

I'd prefer this:

git.add()
    .setUpdate(false)
    .addFilepattern("CHANGELOG.md")
    .addFilepattern("app/build.gradle.kts")
    .addFilePatterns(myfunc())
    .call()

Handily, in Kotlin I can do this with an extension function like this:

fun AddCommand.addFilePatterns(patterns: Collection<String>): AddCommand {
    patterns.forEach { addFilepattern(it) }
    return this
}

But this seems useful enough it should be part of the API.

Alternatives considered

No response

Additional context

No response

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions