seu-as-code / seu-as-code.plugins

The Gradle plugins for SEU-as-code.
Apache License 2.0
28 stars 10 forks source link

Git Plugin: Allow for options to be passed #26

Closed ysb33r closed 7 years ago

ysb33r commented 7 years ago

It would be great is there was additional flexibility to pass arbitrary options to a task to customise the Git behaviour. For instance with gitPullXyz I might want to have the equivalent of git pull --rebase.

Maybe AbstractGitTask can be extended to add some way for options.

lreimer commented 7 years ago

I guess the easiest and quickest to implement (at least for the existing tasks) would be to allow to pass Gradle command line options to the tasks. So you could do:

$ ./gradlew gitPullXyz --rebase

Currently the Git tasks do not support every possible command line option of the Git command when used on the shell that is technically possible. But adding these should be fairly straight forward.

Internally the plugin uses JGit. So the possible options are limited by the JGit API. Having arbitrary options may prove a bit difficult.

Another option I see is to provide some GenericGitTask that basically makes the JGit API scriptable via the build.gradle file. This would give almost arbitrary freedom, e.g.

task gitPullPluginsWithRebase(type: GenericGitTask) {
   git.pull {
      remote "https://github.com/seu-as-code/seu-as-code.plugins.git"
      rebase true
   }
}

What do you think? Would that suite your needs?

ysb33r commented 7 years ago

./gradlew gitPullXyz --rebase

I don't think that would be a great user experience. Also if it is a team's policy to rather rebase than merge, then they would have to rememebr to type this the whole time whereas if it was configurable the just have to run the task.

Internally the plugin uses JGit. So the possible options are limited by the JGit API. Having arbitrary options may prove a bit difficult.

When I said arbitrary, I was fine with it being limited by JGit support

Another option I see is to provide some GenericGitTask that basically makes the JGit API scriptable via the build.gradle file. This would give almost arbitrary freedom

I think having a generic task type is always a useful addition

Overall I have to say that I like the way that defining the repositories ends up in having a number of tasks predefined. (It is a bit like the new model in certain way. it does present a challenge if one would want to configure attributes (which currently does not exist) on of of these tasks.

There could be two alternative DSL way to allows configuration of the standard tasks that are created for a repo. Let's take gitPullFoo as an example task and assume that you have also extended GitPullTask to have

boolean rebase = false

as a property.

In the simplest form the build script author can now do

tasks.whenTaskAdded(GitPullTask) {
  it.rebase = true
}

This will happily work as your plugin only creates the tasks via an afterEvaluate closure.

A second form could be to add the config in the extension DSL

git {
    foo {
        url 'https://foo-server/foo.git'

        options {
           pull {
              rebase = true
           }
        }
    }
}

This provides a slick, communicative DSL to the user, but more of a programming challenge to you as the plugin author. 🎱

lreimer commented 7 years ago

Adding some extra attributes to the Git*Tasks and providing additional extension DSL support should be pretty straight forward to implement.

Once I am done with the Mac support for the Credentials plugin I can start working on this one.

lreimer commented 7 years ago

Just published a RC1 version of the Git plugin to Bintray and the Gradle Plugin portal.

plugins {
    id 'de.qaware.seu.as.code.git' version '2.3.0.RC1'
}

Please check if this suites your needs. Pretty much implemented the DSL configuration way you suggested.

git {
    SeuAsCodePlugins {
        url 'https://github.com/seu-as-code/seu-as-code.plugins.git'

        options {
            pull {
                rebase = true
                timeout = 600
            }
            clone {
                singleBranch = false
                cloneSubmodules = true
                noCheckout = false
                timeout = 300
            }
            push {
                dryRun = true
                pushAll = true
                pushTags = true
                timeout = 200
                force = true
            }
        }
    }
}
ysb33r commented 7 years ago

👍 Will try it over the weekend.

ysb33r commented 7 years ago

I forgot to tell you that the changes you made works very well.