<commit_before>//
// minigit.js tests
//
var minigit = require('../minigit'),
    should = require('should'),
    gutil = require('gulp-util'),
    sh = require('shelljs'),
    path = require('path'),
    _ = require('lodash');

require('mocha');

var repoInit = function () {
    process.env['GIT_WORK_TREE'] = path.resolve(__dirname, 'repo');
    process.env['GIT_DIR'] = path.resolve(process.env['GIT_WORK_TREE'], '.git');

    sh.rm('-rf', process.env['GIT_WORK_TREE']);
    sh.mkdir('-p', process.env['GIT_WORK_TREE']);

    sh.cp('-Rf', mkPath('fixtures/repo/*'.split('/')), process.env['GIT_WORK_TREE']);

    sh.exec('git init', { silent: true });
    sh.exec('git config user.email <EMAIL>', { silent: true });
    sh.exec('git config user.name QA', { silent: true });
    sh.exec('git add -A', { silent: true });
    sh.exec('git commit -am "initial commit"', { silent: true });
};

var repoClean = function() {
    sh.rm('-rf', process.env['GIT_WORK_TREE']);
    delete process.env['GIT_WORK_TREE'];
    delete process.env['GIT_DIR'];
};

var mkPath = function(items) {
    items.unshift(__dirname);

    return items.join(path.sep);
};

var repoAdd = function(src, dst, opts) {
    var from = mkPath(src.split("/")),
        to = mkPath(dst.split("/"));

    sh.mkdir('-p', to);
    sh.cp('-f', from, to);
};

describe('minigit', function() {
    // -
    var options = {
        filter: '\\.(png|jpg)',
        branch: 'HEAD',
        path: 'root/i',
        abbrev: 6,
        message: 'commit changes (urlrevs)'
    };

    beforeEach(function(){
        repoInit();
    });

    afterEach(function(){
        repoClean();
    });

    describe('status()', function() {
        it('should raise exception on unknown repository', function() {
            // setup bogus repo
            process.env['GIT_DIR'] = path.resolve(__dirname, 'bogus');

            minigit.status(options, function(err) {
                should.exist(err);
                err.should.be.an.Error;
                err.message.should.match(/^Unable to get repository status!/);
            });
        });

        it('should not return uncommited changes', function() {
            minigit.status(options, function(err, changed) {
                should.not.exist(err);
                changed.should.be.eql([]);
            });
        });

        it('should not return uncommited changes after foo.txt was added', function(){
            repoAdd("fixtures/foo.txt", "repo");

            minigit.status(options, function(err, changed) {
                should.not.exist(err);
                changed.should.be.eql([]);
            });
        });

        it('should return uncommited changes after bar.png was added', function(){
            repoAdd("fixtures/bar.png", "repo/" + options.path);

            minigit.status(options, function(err, changed) {
                should.not.exist(err);
                changed.length.should.be.eql(1);
            });
        });

    });

    describe('lsTree()', function() {
        it('should raise exception on unknown repository', function() {
            // setup bogus repo
            process.env['GIT_DIR'] = path.resolve(__dirname, 'bogus');

            minigit.lsTree(options, function(err) {
                should.exist(err);
                err.should.be.an.Error;
                err.message.should.match(/^Unable to get repository tree!/);
            });
        });

        it('should return a tree object on valid repository', function() {
            minigit.lsTree(options, function(err, tree) {
                should.not.exist(err);
                tree.should.be.an.Object;
                tree.should.have.keys([ 'root/i/bar.jpg', 'root/i/foo.png' ]);
            });
        });
    });

    describe('add()', function() {
        it('should raise exception on unknown repository', function() {
            // setup bogus repo
            process.env['GIT_DIR'] = path.resolve(__dirname, 'bogus');

            minigit.add(options, function(err) {
                should.exist(err);
                err.should.be.an.Error;
                err.message.should.match(/^Unable to add files to repository!/);
            });
        });

        it('should be done w/o error on valid repository', function() {
            repoAdd("fixtures/bar.png", "repo/" + options.path);

            minigit.add(options, function(err) {
                should.not.exist(err);
            });
        });
    });

    describe('commit()', function() {
        var originalAdd = minigit.add;

        it('should raise exception on unknown repository', function() {

            repoAdd("fixtures/bar.png", "repo/" + options.path);
            minigit.add(options, function(){});

            // spoof MiniGit.add()
            minigit.add = function (params, cb) { return cb(null); };

            // setup bogus repo
            process.env['GIT_DIR'] = path.resolve(__dirname, 'bogus');

            minigit.commit(options, function(err) {
                should.exist(err);
                err.should.be.an.Error;
                err.message.should.match(/^Unable to commit changes!/);
            });
        });

        it('should be done w/o error on valid repository', function() {
            // restore MiniGit.add()
            minigit.add = originalAdd;

            repoAdd("fixtures/bar.png", "repo/" + options.path);

            minigit.commit(options, function(err) {
                should.not.exist(err);
            });
        });
    });
});<commit_msg>minor fixes<commit_after>//
// minigit.js tests
//
var minigit = require('../minigit'),
    should = require('should'),
    sh = require('shelljs'),
    path = require('path'),
    _ = require('lodash');

require('mocha');

var repoInit = function () {
    process.env['GIT_WORK_TREE'] = path.resolve(__dirname, 'repo');
    process.env['GIT_DIR'] = path.resolve(process.env['GIT_WORK_TREE'], '.git');

    sh.rm('-rf', process.env['GIT_WORK_TREE']);
    sh.mkdir('-p', process.env['GIT_WORK_TREE']);

    sh.cp('-Rf', mkPath('fixtures/repo/*'.split('/')), process.env['GIT_WORK_TREE']);

    sh.exec('git init', { silent: true });
    sh.exec('git config user.email <EMAIL>', { silent: true });
    sh.exec('git config user.name QA', { silent: true });
    sh.exec('git add -A', { silent: true });
    sh.exec('git commit -am "initial commit"', { silent: true });
};

var repoClean = function() {
    sh.rm('-rf', process.env['GIT_WORK_TREE']);
    delete process.env['GIT_WORK_TREE'];
    delete process.env['GIT_DIR'];
};

var mkPath = function(items) {
    items.unshift(__dirname);

    return items.join(path.sep);
};

var repoAdd = function(src, dst, opts) {
    var from = mkPath(src.split("/")),
        to = mkPath(dst.split("/"));

    sh.mkdir('-p', to);
    sh.cp('-f', from, to);
};

describe('minigit', function() {
    // various options
    var options = {
        filter: '\\.(png|jpg)',
        branch: 'HEAD',
        path: 'root/i',
        abbrev: 6,
        message: 'commit changes (urlrevs)'
    };

    beforeEach(function(){
        repoInit();
    });

    afterEach(function(){
        repoClean();
    });

    describe('status()', function() {
        it('should raise exception on unknown repository', function() {
            // setup bogus repo
            process.env['GIT_DIR'] = path.resolve(__dirname, 'bogus');

            minigit.status(options, function(err) {
                should.exist(err);
                err.should.be.an.Error;
                err.message.should.match(/^Unable to get repository status!/);
            });
        });

        it('should not return uncommited changes', function() {
            minigit.status(options, function(err, changed) {
                should.not.exist(err);
                changed.should.be.eql([]);
            });
        });

        it('should not return uncommited changes after foo.txt was added', function(){
            repoAdd("fixtures/foo.txt", "repo");

            minigit.status(options, function(err, changed) {
                should.not.exist(err);
                changed.should.be.eql([]);
            });
        });

        it('should return uncommited changes after bar.png was added', function(){
            repoAdd("fixtures/bar.png", "repo/" + options.path);

            minigit.status(options, function(err, changed) {
                should.not.exist(err);
                changed.length.should.be.eql(1);
            });
        });
    });

    describe('lsTree()', function() {
        it('should raise exception on unknown repository', function() {
            // setup bogus repo
            process.env['GIT_DIR'] = path.resolve(__dirname, 'bogus');

            minigit.lsTree(options, function(err) {
                should.exist(err);
                err.should.be.an.Error;
                err.message.should.match(/^Unable to get repository tree!/);
            });
        });

        it('should return a tree object on valid repository', function() {
            minigit.lsTree(options, function(err, tree) {
                should.not.exist(err);
                tree.should.be.an.Object;
                tree.should.have.keys([ 'root/i/bar.jpg', 'root/i/foo.png' ]);
            });
        });
    });

    describe('add()', function() {
        it('should raise exception on unknown repository', function() {
            // setup bogus repo
            process.env['GIT_DIR'] = path.resolve(__dirname, 'bogus');

            minigit.add(options, function(err) {
                should.exist(err);
                err.should.be.an.Error;
                err.message.should.match(/^Unable to add files to repository!/);
            });
        });

        it('should be done w/o error on valid repository', function() {
            repoAdd("fixtures/bar.png", "repo/" + options.path);

            minigit.add(options, function(err) {
                should.not.exist(err);
            });
        });
    });

    describe('commit()', function() {
        var originalAdd = minigit.add;

        it('should raise exception on unknown repository', function() {

            repoAdd("fixtures/bar.png", "repo/" + options.path);
            minigit.add(options, function(){});

            // spoof MiniGit.add()
            minigit.add = function(params, cb) { return cb(null); };

            // setup bogus repo
            process.env['GIT_DIR'] = path.resolve(__dirname, 'bogus');

            minigit.commit(options, function(err) {
                should.exist(err);
                err.should.be.an.Error;
                err.message.should.match(/^Unable to commit changes!/);
            });
        });

        it('should be done w/o error on valid repository', function() {
            // restore MiniGit.add()
            minigit.add = originalAdd;

            repoAdd("fixtures/bar.png", "repo/" + options.path);

            minigit.commit(options, function(err) {
                should.not.exist(err);
            });
        });
    });
});
{'fraction_non_alphanumeric': 0.16533575317604357, 'fraction_numerical': 0.0003629764065335753, 'mean_word_length': 1.9562768240343347, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2440705', 'n_tokens_mistral': 3304, 'n_tokens_neox': 3186, 'n_words': 636}