Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
package-lock.json
6 changes: 6 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
package-lock.json
spoof.sh
LICENSE
.travis.yml
test/
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: node_js
node_js:
- 12
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
28 changes: 28 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
17 changes: 11 additions & 6 deletions forge.js → schmear.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env/node

const { promisify } = require('util');
const exec = promisify(require('child_process').exec);

Expand All @@ -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}"`;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
31 changes: 31 additions & 0 deletions test/schmear.js
Original file line number Diff line number Diff line change
@@ -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');
});
});