rubenv / grunt-git

Git commands for grunt.
MIT License
227 stars 83 forks source link

Added a callback feature to all tasks #92

Closed balanza closed 5 years ago

balanza commented 9 years ago

Hi,

I replicated this pull request after I checked out all jscs formatting issues.

A i mentioned in the previous PR, this edit came out after I needed to move files into another folder after they have been downloaded with a gitpull task.

Modified code chunks lay at line 21 and lines from 27 to 41.

Please consider I can missing something as I'm not an expert grunt-plugin developer. Feel free to ask or modify given code.

Thanks

Emanuele

rubenv commented 9 years ago

This is very non-grunt. Why don't you just add a move task to your Gruntfile, that will be executed after the git task?

balanza commented 9 years ago

Hi,

git tasks are async, thus I need to intercept the very finish (i.e. every file has been pulled) before executing next task (i.e. file moving). I found issues implementing grunt-git task asynchronously, while a simple callback would get the problem solved. As callbacks are javascript's bread'n'butter, as it only needed to modify some spare lines of code and as it added a feature that automatically falls back (if you don't declare a callback, the plugin works as usual), I just did it. Then, I proposed the PR for the sake of sharing my solution.

Obviously, feel free to reject the PR if you think it doesn't fit the plugin.

dylancwood commented 9 years ago

I think that @rubenv is saying is that the grunt tasks typically simulate synchronous behavior. The task will not complete until the git operation has returned. You can therefore chain grunt tasks together, and be confident that one will not start before the previous has finished. Because of this, you can chain tasks together.

Here is an example: grunt.registerTask('pullAndCopy', ['gitpull:master', 'copy:prd'])

This task will run your gitpull task, then your copy task.