src/server/storage/storage.js
function loadRootAndCommitObject(project) {
        var deferred = Q.defer();
        if (data.newHash !== '') {
            project.loadObject(data.newHash)
                .then(function (commitObject) {
                    fullEventData.commitObject = commitObject;
                    return project.loadObject(commitObject.root);
                })
                .then(function (rootObject) {
                    fullEventData.coreObjects.push(rootObject);
                    deferred.resolve(project);
                })
                .catch(function (err) {
                    self.logger.error(err.message);
                    deferred.reject(new Error('Tried to setBranchHash to invalid or non-existing commit, err: ' +
                        err.message));
                });
        } else {
            // When deleting a branch there no need to ensure this.
            deferred.resolve(project);
        }

        return deferred.promise;
    }
function loadRootAndCommitObject(project) {
        var deferred = Q.defer();
        if (data.newHash !== '') {
            project.loadObject(data.newHash)
                .then(function (commitObject) {
                    fullEventData.commitObject = commitObject;
                    return project.loadObject(commitObject.root);
                })
                .then(function (rootObject) {
                    fullEventData.coreObjects.push(rootObject);
                    deferred.resolve(project);
                })
                .catch(function (err) {
                    self.logger.error(err.message);
                    deferred.reject(new Error('Tried to setBranchHash to invalid or non-existing commit, err: ' +
                        err.message));
                });
        } else {
            // When deleting a branch there no need to ensure this.
            deferred.resolve(project);
        }

        return deferred.promise;
    }
function loadRootAndCommitObject ( project ) { var deferred = Q . defer ( ) ; if ( data . newHash !== '' ) { project . loadObject ( data . newHash ) . then ( function ( commitObject ) { fullEventData . commitObject = commitObject ; return project . loadObject ( commitObject . root ) ; } ) . then ( function ( rootObject ) { fullEventData . coreObjects . push ( rootObject ) ; deferred . resolve ( project ) ; } ) . catch ( function ( err ) { self . logger . error ( err . message ) ; deferred . reject ( new Error ( 'Tried to setBranchHash to invalid or non-existing commit, err: ' + err . message ) ) ; } ) ; } else { // When deleting a branch there no need to ensure this. deferred . resolve ( project ) ; } return deferred . promise ; }
This will also ensure that the new commit does indeed point to a commitObject with an existing root.
This will also ensure that the new commit does indeed point to a commitObject with an existing root .