<commit_before>'use strict';

var os = require('os');
var path = require('path');
var grunt = require('grunt');
var git = require('nodegit');

var fixtures = path.join(__dirname, 'fixtures');
var gitFiles = path.join(fixtures, 'git-files');
var spawn = require('child_process').spawn;
var tmpdir = path.join(os.tmpdir(), 'grunt-copy-git-index');
var gitDir = path.join(tmpdir, 'git-repository');
var indexFilesDir = path.join(tmpdir, 'index-files');
var repository;

describe('grunt-copy-git-index', function () {
  describe('when run with no options specified', function () {
    before(function (done) {
      // create git repository

      grunt.file.delete(gitDir, {force: true});
      grunt.file.mkdir(gitDir);

      grunt.file.recurse(gitFiles, function (abspath, rootdir, subdir, filename) {
        grunt.file.copy(abspath, path.join(gitDir, subdir || '', filename));
      });
      git.Repository.init(gitDir, 0).then(function (repo) {
        repository = repo;
        console.log('git workdir:', repo.workdir());
        return repo.index();
      }).then(function (index) {
        var returnCode = index.addByPath('app.js') || index.write();
        if (returnCode) return done(new Error('git add files failed with code ' + returnCode));
        console.log('git add files success');
        done();
      }, done);
    });

    it('should copy files from git index', function () {
    });
  });
});<commit_msg>unittest create a git respository<commit_after>'use strict';

var os = require('os');
var path = require('path');
var grunt = require('grunt');
var git = require('nodegit');

var fixtures = path.join(__dirname, 'fixtures');
var gitFiles = path.join(fixtures, 'git-files');
var gitFilesInRepository = path.join(gitFiles, 'repository');
var gitFilesInIndex = path.join(gitFiles, 'index');
var gitFilesInWork = path.join(gitFiles, 'work');
var spawn = require('child_process').spawn;
var tmpdir = path.join(os.tmpdir(), 'grunt-copy-git-index');
var gitDir = path.join(tmpdir, 'git-repository');
var indexFilesDir = path.join(tmpdir, 'index-files');

describe('grunt-copy-git-index', function () {
  describe('when run with no options specified', function () {
    before(function (done) {
      // Create git repository

      var promiseResults = {};
      grunt.file.delete(gitDir, {force: true});
      grunt.file.mkdir(gitDir);

      git.Repository.init(gitDir, 0).then(function (repo) {
        promiseResults.repository = repo;
        console.log('git workdir:', repo.workdir());
        return repo.index();
      }).then(function (index) {
        promiseResults.index = index;
        grunt.file.recurse(gitFilesInRepository, function (abspath, rootdir, subdir, filename) {
          grunt.file.copy(abspath, path.join(gitDir, subdir || '', filename));
        });
        return index.addAll();
      }).then(function (returnCode) {
        if (returnCode || promiseResults.index.write()) throw new Error('git add files failed with code ' + returnCode);
        console.log('git add files success');

        // Commit files
        return promiseResults.index.writeTree();
      }).then(function (oid) {
        promiseResults.oid = oid;
        var author = git.Signature.now('wmzy', '<EMAIL>');
        var committer = author;
        return promiseResults.repository
          .createCommit('HEAD', author, committer, 'first commit, no HEAD', oid, []);
      }).then(function (commitId) {
        grunt.file.recurse(gitFilesInIndex, function (abspath, rootdir, subdir, filename) {
          grunt.file.copy(abspath, path.join(gitDir, subdir || '', filename));
        });
        return promiseResults.index.addAll();
      }).then(function (returnCode) {
        if (returnCode || promiseResults.index.write()) throw new Error('git add files failed with code ' + returnCode);
        console.log('git add files success');

        grunt.file.recurse(gitFilesInWork, function (abspath, rootdir, subdir, filename) {
          grunt.file.copy(abspath, path.join(gitDir, subdir || '', filename));
        });

        done();
      }).catch(done);
    });

    it('should copy files from git index', function () {
    });
  });
});
{'fraction_non_alphanumeric': 0.15851318944844126, 'fraction_numerical': 0.00047961630695443646, 'mean_word_length': 3.3538622129436324, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '1818125', 'n_tokens_mistral': 1258, 'n_tokens_neox': 1244, 'n_words': 300}