<commit_before>'use strict';

var Git = require('nodegit');
var path = require('path');
var mkdirp = require('mkdirp');
var debug = require('debug')('init');

var add = require('./add');
var config = require('./config');

module.exports = function(o){

    var option = {
        'bare': o.bare || 0,
        'path': o.path,
        'dir': path.resolve(o.path)
    };

    return new Promise(function(resolve, reject){
        mkdirp(option.dir, function(error){
            if (!!error) return reject(error);
            resolve();
        });
    })
    .then(function(){
        debug('repo %s', option.path);
        return Git.Repository.init(option.dir, option.bare);
    })
    .then(function(repo){

        return Promise.all([
            add(repo),
            config.getSignature()
        ])
        .then(function(result){
            return {
                'oid': result[0],
                'author': result[1],
                'committer': result[1],
                'message': 'setup'
            };
        })
        .then(function(data){
            return repo.createCommit('HEAD',
                data.author,
                data.committer,
                data.message,
                data.oid,
                []
            );
        })
        .then(function(oid){
            debug('first commit %s', oid);
            return repo;
        });

    })
    .catch(function(error){
        debug(error);
    });

};<commit_msg>keeps it simpler and adds message option for initial commit<commit_after>'use strict';

var Git = require('nodegit');
var files = require('fildes');
var debug = require('debug')('kit:init');

var add = require('./add');
var config = require('./config');

module.exports = function(dir, o){
    o = o || {};
    var option = {
        'bare': o.bare || 0,
        'message': o.message || 'initial commit'
    };

    return files.mkdir(dir)
    .then(function(){
        debug('repo %s', dir);
        return Git.Repository.init(dir, option.bare);
    })
    .then(function(repo){

        return Promise.all([
            add(repo),
            config.getSignature()
        ])
        .then(function(result){
            return {
                'oid': result[0],
                'author': result[1],
                'committer': result[1],
                'message': option.message
            };
        })
        .then(function(data){
            return repo.createCommit('HEAD',
                data.author,
                data.committer,
                data.message,
                data.oid,
                []
            );
        })
        .then(function(){
            return repo.getBranchCommit('master');
        })
        .then(function(commit){
            return commit.id();
        })
        .then(function(oid){
            debug('first commit %s', oid);
            return repo;
        });

    });

};
{'fraction_non_alphanumeric': 0.15512465373961218, 'fraction_numerical': 0.002770083102493075, 'mean_word_length': 1.5297723292469352, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3768824', 'n_tokens_mistral': 818, 'n_tokens_neox': 787, 'n_words': 164}