src/utils/commit.js
function flush(repoState, driver, commitBuilder, options = {}) {
    options = Object.assign({
        branch: repoState.getCurrentBranch(),
        ignoreEmpty: true
    }, options);

    if (options.ignoreEmpty
        && commitBuilder.isEmpty()
        && commitBuilder.getParents().count() < 2) {
        return Q(repoState);
    }

    // Create new commit
    return driver.flushCommit(commitBuilder)
    // Forward the branch
    .then((commit) => {
        return driver.forwardBranch(options.branch, commit.getSha())
        // Fetch new workingState and replace old one
        .then(function updateBranch() {
            const updated = options.branch.merge({ commit });
            return repoState.updateBranch(options.branch, updated);

        }, function nonFF(err) {
            if (err.code === ERRORS.NOT_FAST_FORWARD) {
                // Provide the created commit to allow merging it back.
                err.commit = commit;
            }
            throw err;
        });
    })
    .then(function updateWorkingState(forwardedRepoState) {
        const forwardedBranch = forwardedRepoState.getBranch(options.branch.getFullName());
        return RepoUtils.fetchTree(forwardedRepoState, driver, forwardedBranch);
    });
}
function flush(repoState, driver, commitBuilder, options = {}) {
    options = Object.assign({
        branch: repoState.getCurrentBranch(),
        ignoreEmpty: true
    }, options);

    if (options.ignoreEmpty
        && commitBuilder.isEmpty()
        && commitBuilder.getParents().count() < 2) {
        return Q(repoState);
    }

    // Create new commit
    return driver.flushCommit(commitBuilder)
    // Forward the branch
    .then((commit) => {
        return driver.forwardBranch(options.branch, commit.getSha())
        // Fetch new workingState and replace old one
        .then(function updateBranch() {
            const updated = options.branch.merge({ commit });
            return repoState.updateBranch(options.branch, updated);

        }, function nonFF(err) {
            if (err.code === ERRORS.NOT_FAST_FORWARD) {
                // Provide the created commit to allow merging it back.
                err.commit = commit;
            }
            throw err;
        });
    })
    .then(function updateWorkingState(forwardedRepoState) {
        const forwardedBranch = forwardedRepoState.getBranch(options.branch.getFullName());
        return RepoUtils.fetchTree(forwardedRepoState, driver, forwardedBranch);
    });
}
Flush a commit from the current branch using a driver
Then update the reference, and pull new workingState
@param {RepositoryState} repoState
@param {Driver} driver
@param {CommitBuilder} commitBuilder
@param {Branch} [options.branch] Optional branch to use instead of
current branch
@param {Boolean} [options.ignoreEmpty=true] Empty commits are
ignored, unless they merge several branches.
@return {Promise<RepositoryState, ERRORS.NOT_FAST_FORWARD>} If the
branch cannot be fast forwarded to the created commit, fails with
NOT_FAST_FORWARD. The error will contains the created Commit.