Code coverage report for tasks/utils/git.js

Statements: 22.58% (7 / 31)      Branches: 0% (0 / 12)      Functions: 5.56% (1 / 18)      Lines: 23.33% (7 / 30)      Ignored: none     

All files » tasks/utils/ » git.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 721 1 1 1   1         1                                                           1                                                              
var Promise = require('es6-promise').Promise;
var exec = require('./exec').exec;
var log = require('./log');
var shell = require("shelljs");
 
function runGitCommand(cmd, args){
    args.unshift(cmd);
    return exec('git', args);
}
 
module.exports = {
    commit : function(comment) {
        if (shell.exec('git status', {silent: true}).output.indexOf('nothing to commit')>-1){
            return Promise.resolve('Nothing to commit');
        } else {
            return exec('git',['commit', '-m', '"' + comment + '"']);
        }
    },
    tag : function(version) {
        return exec('git', ['tag', '-a', version, '-m', version]);
    },
    init : function() {
        return runGitCommand('init', []);
    },
    checkout : function(arrFiles) {
        return runGitCommand('checkout', arrFiles);
    },
    add : function(arrFiles) {
        return runGitCommand('add', arrFiles);
    },
    push : function(arrCmds) {
        return runGitCommand('push', arrCmds);
    },
    rm : function(arrCmds) {
        return runGitCommand('rm', arrCmds);
    },
    remote : function(arrCmds) {
        return runGitCommand('remote', arrCmds);
    },
    user: (function(){
        return {
            name: shell.exec('git config user.name', {silent:true}).output.replace(/\s+$/g, ''),
            email : shell.exec('git config user.email', {silent:true}).output.replace(/\s+$/g, '')
        };
    }()),
    release: function (options){
        var git = this;
        return git.commit(options.tag).then(function() {
            return git.push(['origin', 'master']);
        }).then(function(){
            return git.tag(options.tag).catch(function(msg){
                log.warn(msg);
            });
        }).then(function(){
            if (options.tagged) return Promise.resolve();
            return git.push(['origin', 'master', options.tag]);
        });
    },
    validRepo: function (repo){
        return (
        repo && (repo.match(/.com\:(.*)\//) ||
            repo.match(/http(.*)\/.git/))
        ) ? repo : false;
    },
    checkRemote: function (){
        var repo = shell.exec('git config --get remote.origin.url', {silent:true}).output.replace(/\s+$/g, '');
        return this.validRepo(repo);
    },
    repoUsername: function(repo){
        return (repo.match(/.com\:(.*)\//) && repo.match(/.com\:(.*)\//)[1]) || repo.split('/')[3];
    }
};