<commit_before>var git = require('../');
var rimraf = require('rimraf');
var fs = require( 'fs' );

// Helper functions
var helper = {
  // Test if obj is a true function
  testFunction: function(test, obj, label) {
    // The object reports itself as a function
    test(typeof obj, 'function', label + ' reports as a function.');
    // This ensures the repo is actually a derivative of the Function [[Class]]
    test(toString.call(obj), '[object Function]', label + ' [[Class]] is of type function.');
  },
  // Test code and handle exception thrown
  testException: function(test, fun, label) {
    try {
      fun();
      test(false, label);
    }
    catch (ex) {
      test(true, label);
    }
  }
};

/**
 * Test that the commit object is present.
 *
 * @param  {Object} test
 */
exports.method = function(test){
  test.expect(2);
  helper.testFunction(test.equals, git.commit, 'Commmit');
  test.done();
};

/**
 * Test that
 *
 * @param  {Object} test
 */
exports.improperCommitId = function(test) {
  test.expect(1);
  git.repo('../.git', function(error, repository) {
    repository.commit('not a proper commit sha', function(error, commit) {
      test.notEqual(error, null, 'Error should occur');
      test.done();
    });
  });
};

var historyCountKnownSHA = 'fce88902e66c72b5b93e75bdb5ae717038b221f6';

/**
 * Test that retreiving walking a given commit's history works as expected.
 *
 * @param  {Object} test
 */
exports.history = function(test) {
  test.expect(368);
  git.repo('../.git', function(error, repository) {
    repository.commit(historyCountKnownSHA, function(error, commit) {
      test.equals(error, null, 'Getting latest branch commit should not error');
      var historyCount = 0;
      var expectedHistoryCount = 364;
      commit.history().on('commit', function(error, commit) {
        test.equals(error, null, 'There should be no errors');
        historyCount++;
      }).on('end', function(error, commits) {
        test.equals(error, null, 'There should be no errors');
        test.equals(historyCount, expectedHistoryCount, 'Manual count does not match expected');
        test.equals(commits.length, expectedHistoryCount, '"end" count does not match expected');

        test.done();
      });
    });
  });
};

/**
 * Test that retreiving master branch's HEAD commit works as expected.
 *
 * @param  {Object} test
 */
exports.masterHead = function(test) {
  test.expect(2);
  git.repo('../.git', function(error, repository) {
    repository.branch('master', function(error, branch) {

      test.equals(error, null, 'Getting branch should not error');

      repository.commit(branch.sha, function(error, commit) {

        test.equals(error, null, 'Getting latest branch commit should not error');

        test.done();
      });
    });
  });
};

/**
 * Test that retreiving parent works as expected.
 *
 * @param  {Object} test
 */
exports.parentSync = function(test) {
  test.expect(2);
  git.repo('../.git', function(error, repository) {
    repository.commit('2d71044741412280370cb0326c96d3a5a7b5dca1', function(error, commit) {
      test.equals(commit.parentCount, 1, 'Commit has exactly one parent');
      var parent = commit.parentSync(0);
      test.equals(parent.sha, 'e8876707938abf94d5cc02b0c4017c4fec2aa44e', 'Parent SHA should match expected value');
      test.done();
    });
  });
};

/**
 * Test that retreiving parent works as expected.
 *
 * @param  {Object} test
 */
exports.parent = function(test) {
  test.expect(2);
  git.repo('../.git', function(error, repository) {
    repository.commit('2d71044741412280370cb0326c96d3a5a7b5dca1', function(error, commit) {
      test.equals(commit.parentCount, 1, 'Commit has exactly one parent');
      commit.parent(0, function(error, parent) {
        if (error) throw error;
        test.equals(parent.sha, 'e8876707938abf94d5cc02b0c4017c4fec2aa44e', 'Parent SHA should match expected value');
        test.done();
      });

    });
  });
};

/**
 * Test that retrieving and walking a commit's tree works as expected.
 *
 * @param  {Object} test
 */
exports.tree = function(test) {
  test.expect(2);
  git.repo('../.git', function(error, repository) {

    repository.commit(historyCountKnownSHA, function(error, commit) {

      test.equals(error, null, 'Getting latest branch commit should not error');

      var commitTreeEntryCount = 0;
      var expectedCommitTreeEntryCount = 200;

      commit.tree().walk().on('entry', function(commit) {
        commitTreeEntryCount++;
      }).on('end', function(commits) {

        test.equals(commitTreeEntryCount, expectedCommitTreeEntryCount, 'Commit tree entry count does not match expected');

        test.done();
      });
    });
  });
};
<commit_msg>Updated convenience-commit tests<commit_after>var git = require('../');
var rimraf = require('rimraf');
var fs = require( 'fs' );

// Helper functions
var helper = {
  // Test if obj is a true function
  testFunction: function(test, obj, label) {
    // The object reports itself as a function
    test(typeof obj, 'function', label + ' reports as a function.');
    // This ensures the repo is actually a derivative of the Function [[Class]]
    test(toString.call(obj), '[object Function]', label + ' [[Class]] is of type function.');
  },
  // Test code and handle exception thrown
  testException: function(test, fun, label) {
    try {
      fun();
      test(false, label);
    }
    catch (ex) {
      test(true, label);
    }
  }
};

/**
 * Test that the commit object is present.
 *
 * @param  {Object} test
 */
exports.method = function(test){
  test.expect(2);
  helper.testFunction(test.equals, git.commit, 'Commmit');
  test.done();
};

/**
 * Test that
 *
 * @param  {Object} test
 */
exports.improperCommitId = function(test) {
  test.expect(1);
  git.repo('../.git', function(error, repository) {
    repository.commit('not a proper commit sha', function(error, commit) {
      test.notEqual(error, null, 'Error should occur');
      test.done();
    });
  });
};

var historyCountKnownSHA = 'fce88902e66c72b5b93e75bdb5ae717038b221f6';

/**
 * Test that retreiving walking a given commit's history works as expected.
 *
 * @param  {Object} test
 */
exports.history = function(test) {
  test.expect(368);
  git.repo('../.git', function(error, repository) {
    repository.commit(historyCountKnownSHA, function(error, commit) {
      test.equals(null, error, 'Getting latest branch commit should not error');
      var historyCount = 0;
      var expectedHistoryCount = 364;
      commit.history().on('commit', function(error, commit) {
        test.equals(null, error, 'There should be no errors');
        historyCount++;
      }).on('end', function(error, commits) {
        test.equals(null, error, 'There should be no errors');
        test.equals(historyCount, expectedHistoryCount, 'Manual count does not match expected');
        test.equals(commits.length, expectedHistoryCount, '"end" count does not match expected');

        test.done();
      });
    });
  });
};

/**
 * Test that retreiving master branch's HEAD commit works as expected.
 *
 * @param  {Object} test
 */
exports.masterHead = function(test) {
  test.expect(2);
  git.repo('../.git', function(error, repository) {
    repository.branch('master', function(error, branch) {

      test.equals(error, null, 'Getting branch should not error');

      repository.commit(branch.sha, function(error, commit) {

        test.equals(error, null, 'Getting latest branch commit should not error');

        test.done();
      });
    });
  });
};

/**
 * Test that retreiving parent works as expected.
 *
 * @param  {Object} test
 */
exports.parentSync = function(test) {
  test.expect(2);
  git.repo('../.git', function(error, repository) {
    repository.commit('2d71044741412280370cb0326c96d3a5a7b5dca1', function(error, commit) {
      test.equals(commit.parentCount, 1, 'Commit has exactly one parent');
      var parent = commit.parentSync(0);
      test.equals(parent.sha, 'e8876707938abf94d5cc02b0c4017c4fec2aa44e', 'Parent SHA should match expected value');
      test.done();
    });
  });
};

/**
 * Test that retreiving parent works as expected.
 *
 * @param  {Object} test
 */
exports.parent = function(test) {
  test.expect(2);
  git.repo('../.git', function(error, repository) {
    repository.commit('2d<PASSWORD>74141<PASSWORD>70cb<PASSWORD>a<PASSWORD>1', function(error, commit) {
      test.equals(commit.parentCount, 1, 'Commit has exactly one parent');
      commit.parent(0, function(error, parent) {
        if (error) throw error;
        test.equals(parent.sha, 'e8876707938abf94d5cc02b0c4017c4fec2aa44e', 'Parent SHA should match expected value');
        test.done();
      });

    });
  });
};

/**
 * Test that retrieving and walking a commit's tree works as expected.
 *
 * @param  {Object} test
 */
exports.tree = function(test) {
  test.expect(2);
  git.repo('../.git', function(error, repository) {

    repository.commit(historyCountKnownSHA, function(error, commit) {

      test.equals(error, null, 'Getting latest branch commit should not error');

      var commitTreeEntryCount = 0;
      var expectedCommitTreeEntryCount = 200;

      commit.tree().walk().on('entry', function(commit) {
        commitTreeEntryCount++;
      }).on('end', function(commits) {

        test.equals(commitTreeEntryCount, expectedCommitTreeEntryCount, 'Commit tree entry count does not match expected');

        test.done();
      });
    });
  });
};

{'fraction_non_alphanumeric': 0.14718294998944925, 'fraction_numerical': 0.029964127453049168, 'mean_word_length': 3.3641804788213627, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6244501', 'n_tokens_mistral': 3065, 'n_tokens_neox': 2899, 'n_words': 752}