rubenv/grunt-git — pull request #58 by dylancwood (2014-06-20 06:05:43+00:00)
Title: Add cwd option

Resolves #36 and #41.

This pull request adds interpretation of a new option in tasks/git.js: cwd. If the option is set, then the option's value is validated as an existing path.

I ran into difficulty when trying to apply a unit test to the tasks/git.js file. Perhaps some of the collaborators on this repo can provide a solution for unit testing a dynamic grunt task wrapper. In leau of unit testing, I performed some simple functional testing:

I created a test directory with a Gruntfile and loaded grunt-git via npm install. I then copied the new tasks/git.js over the existing one in node_module/grunt-git. Finally, I created a sub-directory called ``test_dir``. I then created a simple Gruntfile as shown below:
```js
module.exports = function (grunt) {
grunt.initConfig({
gitclone: {
gruntgit: {
options:{
repository: "https://github.com/rubenv/grunt-git.git",
directory: "<%= grunt.option('customDir') %>"
}
}
},
gitpull: {
gruntgit: {
options:{
cwd: "<%= grunt.option('customDir') %>"
}
}
}
});

grunt.loadNpmTasks('grunt-git');
};
```

Next, I issued the following commands to test that the cwd option worked, and caught errors as expected:

```
harmony:grunt-git-test dylan$ ls
Gruntfile.js	node_modules	package.json	test_dir	typescript

harmony:grunt-git-test dylan$ grunt gitclone --customDir="test_dir/custom_name"
Running "gitclone:gruntgit" (gitclone) task

Done, without errors.
harmony:grunt-git-test dylan$ grunt gitpull --customDir="test_dir/custom_name"
Running "gitpull:gruntgit" (gitpull) task

Done, without errors.
harmony:grunt-git-test dylan$ grunt gitpull --customDir="error_dir/custom_name"
Running "gitpull:gruntgit" (gitpull) task
Warning: The specified cwd does not exist: "error_dir/custom_name" Use --force to continue.

Aborted due to warnings.
```

Please let me know if you have any feedback or questions.