Skip to content
This repository was archived by the owner on Dec 2, 2026. It is now read-only.
This repository was archived by the owner on Dec 2, 2026. It is now read-only.

Repository.createCommitOnHead ignores filesToAdd argument #655

Closed

Description

@freder

hi,

it looks like Repository.createCommitOnHead ignores the first argument filesToAdd. it is not using it at all, and instead adds all the files!

and that is why this function to create empty commits doesn't work as expected when there are (unstaged) files with changes:

function createEmptyCommit(repo, message, sig) {
    var files = []; // <--
    sig = sig || createSignature();
    var author = sig;
    var committer = sig;

    return unstageAll(repo) // make sure commit is in fact empty. (does a mixed reset)
        .then(function() {
            return repo.createCommitOnHead(
                files,
                author,
                committer,
                message
            );
        })
        .catch(function(err) {
            handleError(err);
        });
}

Activity

  1. freder commented on Jul 31, 2015

    @freder
    Author

    using this for now

    function createCommitOnHead(filesToAdd, author, committer, message) {
        var index, repo;
        return getRepo()
            .then(function(repo_) {
                repo = repo_;
                return repo.openIndex();
            })
            .then(function(index_) {
                index = index_;
                index.read(1);
                if (!filesToAdd) { filesToAdd = []; }
                var result = filesToAdd.map(function(item) {
                    return index.addByPath(item);
                });
                return Q.all(result);
            })
            .then(function() {
                index.write();
                return index.writeTree();
            }).then(function(treeOid) {
                return repo.getHeadCommit()
                    .then(function(parent) {
                        return repo.createCommit(
                            'HEAD',
                            author,
                            committer,
                            message,
                            treeOid,
                            [parent]
                        );
                    });
            }).
            catch(handleError);
    };
  2. tbranyen commented on Jul 31, 2015

    @tbranyen
    Member

    Can you PR that?

  3. rcjsuen commented on Jan 6, 2017

    @rcjsuen
    Member

    Can this be closed? #656 was closed but the corresponding #670 has been merged into master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions