Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit 0744127

Browse files
committed
Merge branch 'release/v0.3.0'
* release/v0.3.0: bump v0.3.0 (git config) use execWrap for better output (git config) added qoutes around config value (tests) corrected grunt's loadTask path (readme) added an example for config Use async Add remote and connectCommits fix Fix some review notes from @kevenawoo Updates Add git config options
2 parents e9c1234 + 29afd40 commit 0744127

File tree

6 files changed

+81
-2
lines changed

6 files changed

+81
-2
lines changed

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,15 @@ Default: `true`
135135

136136
Make sure that every commit on the built code branch matches a commit on the main project branch. If the main project's working directory has uncommitted changes, a commit task will throw an error.
137137

138+
139+
#### config
140+
Type: `Object`
141+
Default: `{}`
142+
143+
Optional [git config](http://git-scm.com/docs/git-config) settings for the repository when preparing the repository.
144+
ex: `{'user.name': 'John Doe'}`
145+
146+
138147
### Usage
139148

140149
A common use of grunt-build-control is to commit and push built code to the GitHub pages branch of the main repository, or to the master branch of a git-based deployment server like Heroku.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "grunt-build-control",
33
"description": "Automate version control tasks for your project's built code. Keep built code in sync with source code, maintain multiple branches of built code, commit with automatic messages, and push to remote repositories.",
4-
"version": "0.2.2",
4+
"version": "0.3.0",
55
"homepage": "https://github.com/robwierzbowski/grunt-build-control",
66
"author": "Rob Wierzbowski <[email protected]> (http://robwierzbowski)",
77
"repository": {

tasks/build_control.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ module.exports = function (grunt) {
3232
tag: false,
3333
push: false,
3434
message: 'Built %sourceName% from commit %sourceCommit% on branch %sourceBranch%',
35-
connectCommits: true
35+
connectCommits: true,
36+
config: {}
3637
});
3738

3839
var tokens = {
@@ -160,6 +161,15 @@ module.exports = function (grunt) {
160161
}
161162
}
162163

164+
165+
// Initialize the git config
166+
function initConfig() {
167+
for (var key in options.config) {
168+
execWrap('git config "' + key + '" "' + options.config[key] + '"');
169+
}
170+
}
171+
172+
163173
// Create a named remote if one doesn't exist
164174
function initRemote () {
165175
remoteName = "remote-" + crypto.createHash('md5').update(options.remote).digest('hex').substring(0, 6);
@@ -289,6 +299,7 @@ module.exports = function (grunt) {
289299

290300
// Set up repository
291301
initGit();
302+
initConfig();
292303

293304
remoteName = options.remote;
294305

test/scenarios/git config/repo/dist/empty_file

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module.exports = function (grunt) {
2+
// add custom tasks
3+
// NOTE: cwd is `test/mock`
4+
grunt.loadTasks('../../../tasks');
5+
6+
7+
// test config
8+
grunt.initConfig({
9+
buildcontrol: {
10+
options: {
11+
dir: 'dist',
12+
config: {
13+
"user.name": "John Doe",
14+
"user.email": "[email protected]"
15+
},
16+
remote: '../../remote',
17+
connectCommits: false
18+
},
19+
deploy: {
20+
options: {
21+
branch: 'master',
22+
commit: true,
23+
message: 'git config deploy message',
24+
push: true
25+
}
26+
}
27+
}
28+
});
29+
30+
// default task
31+
grunt.registerTask('default', ['buildcontrol:deploy']);
32+
};

test/tests.js

+27
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,33 @@ describe('buildcontrol', function() {
523523
});
524524

525525

526+
describe('git config', function(done) {
527+
it('should set git config variables properly', function(done) {
528+
var tasks = [];
529+
530+
tasks.push(function(next) {
531+
childProcess.exec('git init', {cwd: 'repo/dist'}, next);
532+
});
533+
534+
tasks.push(function(next) {
535+
execScenario(function(err, stdout, stderr) {
536+
should.not.exist(err);
537+
next(err);
538+
});
539+
});
540+
541+
tasks.push(function(next) {
542+
childProcess.exec('git config user.name', {cwd: 'repo/dist'}, function(err, stdout, stderr) {
543+
stdout.should.have.string('John Doe');
544+
next(err);
545+
});
546+
});
547+
548+
async.series(tasks, done);
549+
});
550+
});
551+
552+
526553
describe('deploy to named remote', function() {
527554
it('should have deployed to origin', function(done) {
528555
var tasks = [];

0 commit comments

Comments
 (0)