Skip to content

Commit

Permalink
support keepHistory (or --keep-history) flag (#39)
Browse files Browse the repository at this point in the history
* feat(fetch): support keepHistory (or --keep-history) flag

if given, pollinate won't delete the .git directory

* feat(fetch): support keepHistory (or --keep-history) flag

if given, pollinate won't delete the .git directory

* style(general): fix jslint errors

* Update init.js

* Update init.js

* Update bin.js
  • Loading branch information
jedwards1211 authored and howardroark committed Feb 20, 2017
1 parent 1fa2745 commit d22cb67
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 15 deletions.
5 changes: 4 additions & 1 deletion bin.js 100644 → 100755
Expand Up @@ -15,6 +15,8 @@ var program = require('commander');
var parse = require('cli-argparse');
var pollinate = require('./lib/index.js');

var parsed = parse(process.argv, {camelcase: false});

program
.version(require('./package.json').version)
.usage('template [data]');
Expand All @@ -35,7 +37,8 @@ if (program.args.length < 1) {

pollinate({
inputs: program.args,
options: parse(process.argv, {camelcase: false}).options
options: parsed.options,
flags: parsed.flags
}, function (err, result) {
if (err) {
console.log(err);
Expand Down
2 changes: 1 addition & 1 deletion lib/fetch.js
Expand Up @@ -125,7 +125,7 @@ var fetchGit = function (state, callback) {
}
},
function (next) {
if (isDirectory(tmpPath + '/.git')) {
if (isDirectory(tmpPath + '/.git') && !state.options.keepHistory && !(state.flags && state.flags['keep-history'])) {
fsExtra.remove(tmpPath + '/.git', function (err) {
if (err) {
next(err);
Expand Down
76 changes: 63 additions & 13 deletions tests/test.js
@@ -1,4 +1,4 @@
/*global describe, it*/
/*global describe, it, afterEach*/
'use strict';

var pollinate = require('../lib/index.js');
Expand All @@ -8,6 +8,12 @@ var fs = require('fs');
var path = require('path');

describe('Test basic example', function () {
afterEach(function (done) {
rimraf('newproject', function () {
rimraf('test', done);
});
});

it('GitHub with json string', function (done) {
this.timeout(10000);
pollinate({
Expand All @@ -24,7 +30,7 @@ describe('Test basic example', function () {
fs.readFile(path.join('newproject', 'README.md'), 'utf8', function (err, data) {
assert.isNull(err);
assert.notInclude(data, 'This branch is for testing `pollinate howardroark/webapp#test-branch`.');
rimraf('newproject', done);
done();
});
});
});
Expand All @@ -41,7 +47,7 @@ describe('Test basic example', function () {
}, function (err, result) {
assert.isNull(err);
assert.isObject(result);
rimraf('newproject', done);
done();
});
});
it('GitHub with json url', function (done) {
Expand All @@ -57,7 +63,7 @@ describe('Test basic example', function () {
}, function (err, result) {
assert.isNull(err);
assert.isObject(result);
rimraf('newproject', done);
done();
});
});
it('Git with json string', function (done) {
Expand All @@ -73,7 +79,51 @@ describe('Test basic example', function () {
}, function (err, result) {
assert.isNull(err);
assert.isObject(result);
rimraf('newproject', done);
done();
});
});
it('Git with json string and keepHistory', function (done) {
this.timeout(10000);
pollinate({
"inputs": [
"https://github.com/howardroark/webapp.git",
"{\"name\":\"newproject\",\"container\":\"alpine\"}"
],
"options": {
"keepHistory": true
//..
}
}, function (err, result) {
assert.isNull(err);
assert.isObject(result);
fs.stat(path.join('newproject', '.git'), function (err, stats) {
assert.isNull(err);
assert.isOk(stats.isDirectory());
done();
});
});
});
it('Git with json string and --keep-history', function (done) {
this.timeout(10000);
pollinate({
"inputs": [
"https://github.com/howardroark/webapp.git",
"{\"name\":\"newproject\",\"container\":\"alpine\"}"
],
"options": {
//..
},
"flags": {
"keep-history": true
}
}, function (err, result) {
assert.isNull(err);
assert.isObject(result);
fs.stat(path.join('newproject', '.git'), function (err, stats) {
assert.isNull(err);
assert.isOk(stats.isDirectory());
done();
});
});
});
it('GitHub with options', function (done) {
Expand All @@ -89,7 +139,7 @@ describe('Test basic example', function () {
}, function (err, result) {
assert.isNull(err);
assert.isObject(result);
rimraf('test', done);
done();
});
});
it('GitHub with ref', function (done) {
Expand All @@ -108,7 +158,7 @@ describe('Test basic example', function () {
fs.readFile(path.join('newproject', 'README.md'), 'utf8', function (err, data) {
assert.isNull(err);
assert.include(data, 'This branch is for testing `pollinate howardroark/webapp#test-branch`.');
rimraf('newproject', done);
done();
});
});
});
Expand All @@ -128,7 +178,7 @@ describe('Test basic example', function () {
fs.readFile(path.join('newproject', 'README.md'), 'utf8', function (err, data) {
assert.isNull(err);
assert.include(data, 'This branch is for testing `pollinate howardroark/webapp#test-branch`.');
rimraf('newproject', done);
done();
});
});
});
Expand All @@ -145,7 +195,7 @@ describe('Test basic example', function () {
}, function (err, result) {
assert.isNull(err);
assert.isObject(result);
rimraf('newproject', done);
done();
});
});
it('Local path without template.json, json file with discard omitted', function (done) {
Expand All @@ -161,7 +211,7 @@ describe('Test basic example', function () {
}, function (err, result) {
assert.isNull(err);
assert.isObject(result);
rimraf('newproject', done);
done();
});
});
it('Local path without template.json, json file with parse set to all', function (done) {
Expand All @@ -177,7 +227,7 @@ describe('Test basic example', function () {
}, function (err, result) {
assert.isNull(err);
assert.isObject(result);
rimraf('newproject', done);
done();
});
});
it('Local path without template.json, json file with move omitted', function (done) {
Expand All @@ -193,7 +243,7 @@ describe('Test basic example', function () {
}, function (err, result) {
assert.isNull(err);
assert.isObject(result);
rimraf('newproject', done);
done();
});
});
it('Local path without template.json, json file with complete', function (done) {
Expand All @@ -209,7 +259,7 @@ describe('Test basic example', function () {
}, function (err, result) {
assert.isNull(err);
assert.isObject(result);
rimraf('newproject', done);
done();
});
});
});

0 comments on commit d22cb67

Please sign in to comment.