var immutable = require('immutable');

var CommitBuilder = require('../models/commitBuilder');
var WorkingUtils = require('./working');
var RepoUtils = require('./repo');


/**
 * Create a commit builder from a workingState
 * @param {RepositoryState}
 * @param {Object} [opts] Options object
 * @param {Author} [opts.author]
 * @param {String} [opts.message]
 */
function prepareCommit(repoState, opts) {
    var workingState = repoState.getCurrentState();
    var changes = workingState.getChanges();

    // Parent SHA
    opts.parents = new immutable.List([
        workingState.getHead()
    ]);

    // Default commit message
    opts.message = opts.message || workingState.getCommitMessage();

    // Get merged tree (with applied changes)
    opts.treeEntries = WorkingUtils.getMergedTreeEntries(workingState);

    // Create map of blobs that needs to be created
    opts.blobs = changes.filter(function (change) {
        return !change.hasSha();
    }).map(function (change) {
        return change.getContent();
    });

    return new CommitBuilder(opts);
}

/**
 * Flush a commit using a driver
 * Then update the reference, pull new workingState
 * @return {Promise<RepositoryState>}
 */
function flush(driver, repoState, commitBuilder) {
    var currentBranch = repoState.getCurrentBranch();

    // Create new commit
    return driver.flushCommit(commitBuilder)

    // Update reference
    .then(function(commit) {
        return driver.flushRef(currentBranch.getName(), commit.getSha());
    })

    // Fetch new workingState and replace old one
    .then(function() {
        return RepoUtils.fetchBranch(repoState, driver, currentBranch);
    });
}

module.exports = {
    prepare: prepareCommit,
    flush: flush
};

@@ -353,16 +353,43 @@
 essage%5D%0A
+ * @return %7BCommitBuilder%7D%0A
  */%0Afunc
@@ -1158,16 +1158,20 @@
 ference,
+ and
  pull ne
@@ -1181,24 +1181,128 @@
 orkingState%0A
+ * @param %7BRepositoryState%7D repoState%0A * @param %7BDriver%7D driver%0A * @param %7BCommitBuilder%7D commitBuilder%0A
  * @return %7B
@@ -1346,24 +1346,16 @@
 n flush(
-driver, 
 repoStat
@@ -1356,16 +1356,24 @@
 poState,
+ driver,
  commitB

Fix CommitUtils doc