diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d5f19d8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +package-lock.json diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..be438b5 --- /dev/null +++ b/.npmignore @@ -0,0 +1,6 @@ +node_modules +package-lock.json +spoof.sh +LICENSE +.travis.yml +test/ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..c7b016c --- /dev/null +++ b/.travis.yml @@ -0,0 +1,3 @@ +language: node_js +node_js: + - 12 diff --git a/README.md b/README.md index d41a545..7f086ac 100644 --- a/README.md +++ b/README.md @@ -7,18 +7,21 @@ minute. ## Running yourself ```sh -cd /repo/you/want/to/spoof/ -cp /path/to/this/repo/forge.js . -node forge.js +npm install -g git-schmear ``` If you want to spoof a fresh repo, copy over `spoof.sh` to get yourself some freshly minted commits. You can see [this](schmeared) repo for an example of a repo that has been `git-schmeared`. +## Testing ![](https://travis-ci.com/SivanMehta/git-schmear.svg?branch=master) + +``` +npm test +``` + ## TODO -- ~~literally any testing~~ - Variable intervals of schmear, as opposed to 1 day intervals. - Preserving `git` authorship, which is currently blown away. - Take start time as a CLI parameter and distribute commits from then until now. diff --git a/package.json b/package.json new file mode 100644 index 0000000..ca0c33b --- /dev/null +++ b/package.json @@ -0,0 +1,28 @@ +{ + "name": "git-schmear", + "version": "0.0.0", + "scripts": { + "test": "npm run test:unit && npm run test:lint", + "test:unit": "mocha test/*.js", + "test:lint": "eslint-godaddy schmear.js" + }, + "bin": { + "schmear": "./schmear.js" + }, + "keywords": [ + "git", + "schmear", + "spoof", + "time-travel" + ], + "devDependencies": { + "eslint": "^6.3.0", + "eslint-config-godaddy": "^4.0.0", + "eslint-plugin-json": "^1.4.0", + "eslint-plugin-mocha": "^6.1.0", + "mocha": "^6.2.2", + "proxyquire": "^2.1.3", + "sinon": "^7.5.0" + }, + "main": "schmear.js" +} diff --git a/forge.js b/schmear.js similarity index 92% rename from forge.js rename to schmear.js index 17b9521..0b8158d 100644 --- a/forge.js +++ b/schmear.js @@ -1,3 +1,5 @@ +#!/usr/bin/env/node + const { promisify } = require('util'); const exec = promisify(require('child_process').exec); @@ -10,7 +12,7 @@ const today = new Date(); * * @param {String} message - String of what the commit originally was * @param {String} day - When the commit "happened" - * @return {String} formatted `git commit` command + * @returns {String} formatted `git commit` command */ function formCommit(message, day) { return `GIT_COMMITTER_DATE="${day}" git commit -m "${message}" --date "${day}"`; @@ -64,7 +66,7 @@ class Runner { const message = lines.slice(0, lines.length - 2).join('\n'); // The first commit is a special case because we cannot `git reset`. - if (idx == 1) { + if (idx === 1) { await exec('git update-ref -d HEAD'); const day = this.formDay(0); const commit = formCommit(message, day); @@ -94,15 +96,18 @@ class Runner { const commit = formCommit(message, day); await exec(commit); - if(this.messageStack.length > 0) { + if (this.messageStack.length > 0) { const { stdout } = await exec('git stash list | wc -l'); - const completed = this.days - parseInt(stdout.match(/[0-9]+/)[0]); + const completed = this.days - parseInt(stdout.match(/[0-9]+/)[0], 10); await this.rebuildRepo(completed + 1); } } } -(async function () { +async function run() { const runner = new Runner(); await runner.start(); -})(); +} + +if (!module.parent) run(); +module.exports = Runner; diff --git a/test/schmear.js b/test/schmear.js new file mode 100644 index 0000000..30504ea --- /dev/null +++ b/test/schmear.js @@ -0,0 +1,31 @@ +const proxyquire = require('proxyquire'); + +function exec(cmd, cb) { + cb(null, { stdout: cmd }); +} + +describe('Commiting Forgery', function () { + let Runner; + beforeEach(function () { + const Schmear = proxyquire('../', { + 'child_process': ({ exec }) + }); + + Runner = new Schmear(); + }); + + it('exposes a class'); + it('formDay'); + + describe('buildStack', function () { + it('does some stuff'); + }); + + describe('rebuildRepo', function () { + it('does some stuff'); + }); + + describe('start', function () { + it('does some stuff'); + }); +});