feat: Command method to return the equivalent `git` command string

Offen
#248 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Anfängerfreundlichkeit
38/100
Issue-Typ
Feature
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
git, java

Rechercherichtung

Start by locating the *Command classes and how they represent their options and arguments; the issue does not name specific files or tests. Determine how command strings could cover the command types and support a caller-provided function; done means each command can expose its equivalent git invocation, with tests covering the formatting and callback behavior.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

enhancement
Description

I'd like a method on each *Command that either returns a string or passes the string to a caller-provided function.

The string should be the equivalent git command line invocation for the command.

Motivation

I'm writing automation, and I want to log the git operations the automation is performing. A natural way to do this is to log the operations as the equivalent git commands.

  1. The people reviewing the logs are familiar with git.
  2. In case of a problem it makes it easy to manually walk through the same operations the automation performed by copy/pasting the command.

Right now I'm doing this in Kotlin, and can do this with a lot of extension functions and some reflection to get at private properties. For example, for AddCommand:

inline fun <reified T : Any, R> T.getPrivateProperty(name: String): R? {
    val field = this::class.java.getDeclaredField(name)
    field.isAccessible = true
    @Suppress("UNCHECKED_CAST")
    return field.get(this) as R?
}

fun AddCommand.info(t: Terminal): AddCommand {
    val update = if (getPrivateProperty<AddCommand, Boolean>("update") == true) " --update" else ""
    val filePatterns = getPrivateProperty<AddCommand, Collection<String>>("filepatterns")
        ?.joinToString(" ")

    t.info("- git add$update $filePatterns")
    return this
}

and then the call site looks like this:

val t = Terminal()

git.add()
    .setUpdate(false)
    .addFilePattern("foo")
    .info(t)
    .call()

which (for my use case) prints

- git add foo

to the terminal when this runs. This is specific to my use case and isn't very general, which is why I suggest the JGit equivalent (if implemented) should take a caller-provided function which receives the command string and decides what to do with it.

Alternatives considered

No response

Additional context

No response

Vorherrschende Sprache
Java
Sterne
427
Forks
116
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus eclipse-jgit/jgit

Alle Issues in eclipse-jgit/jgit

Ähnliche Issues

Weitere Issues zu Java

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.