Passed
Branch master (5b3840)
by Björn
03:20
created

T_VAR   A

Complexity

Total Complexity 35
Complexity/F 1.46

Size

Lines of Code 1
Function Count 24

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 1 Features 1
Metric Value
dl 0
loc 1
ccs 1
cts 1
cp 1
rs 9
noi 2
c 1
b 1
f 1
cc 0
wmc 35
nc 32
mnd 1
bc 32
fnc 24
crap 0
bpm 1.3333
cpm 1.4583
1 1
var childProcess = require('child_process');
2
3 1
module.exports = {
4
  debug: function(callback) {
5
    childProcess.exec('git remote -v', {}, function(err, remotes) {
6 2
      if (err) {
7
        throw new Error('git.remote: ' + err.message);
8
      }
9
10
      childProcess.exec('git branch -a', {}, function(err, branches) {
11 2
        if (err) {
12
          throw new Error('git.branch: ' + err.message);
13
        }
14
15
        callback(remotes, branches);
16
      });
17
    });
18
  },
19
  clean: function(callback) {
20
    childProcess.exec('git diff-index --name-only HEAD --', {}, function(err, stdout) {
21 2
      callback(undefined, !err && !stdout);
22
    });
23
  },
24
25
  commitInfo: function(callback) {
26
    module.exports.head(function(err, headSha) {
27
      module.exports.master(function(err, masterSha) {
28
        module.exports.tagName(function(err, tagName) {
29
          callback(undefined, {
30
            head: headSha,
31
            master: masterSha,
32
            tagName: tagName,
33
            isMaster: headSha === masterSha
34
          });
35
        });
36
      });
37
    });
38
  },
39
40
  head: function(callback) {
41
    childProcess.exec('git rev-parse --short HEAD', {}, function(err, stdout) {
42 2
      if (err) {
43
        throw new Error('git.head: ' + err.message);
44
      }
45
46
      callback(undefined, stdout.trim());
47
    });
48
  },
49
  master: function(callback) {
50
    childProcess.exec('git rev-parse --short origin/master', {}, function(err, stdout) {
51
      // This will error if master was not checked out but in this case we know we are not master
52
      // so we can ignore.
53 4
      if (err && !(/Needed a single revision/.test(err.message))) {
54
        throw new Error('git.master: ' + err.message);
55
      }
56
57
      callback(undefined, stdout.trim());
58
    });
59
  },
60
61
  add: function(path, callback) {
62
    childProcess.exec('git add -f ' + path, {}, function(err) {
63 2
      if (err) {
64
        throw new Error('git.add: ' + err.message);
65
      }
66
67
      callback();
68
    });
69
  },
70
  commit: function(name, callback) {
71
    childProcess.exec('git commit --message=' + name, {}, function(err) {
72 2
      if (err) {
73
        throw new Error('git.commit: ' + err.message);
74
      }
75
76
      callback();
77
    });
78
  },
79
  tag: function(name, callback) {
80
    childProcess.exec('git tag -a --message=' + name + ' ' + name, {}, function(err) {
81 2
      if (err) {
82
        throw new Error('git.tag: ' + err.message);
83
      }
84
85
      callback();
86
    });
87
  },
88
  tagName: function(callback) {
89
    childProcess.exec('git describe --tags', {}, function(err, stdout) {
90 2
      if (err) {
91
        throw new Error('git.tagName: ' + err.message);
92
      }
93
94
      var tags = stdout.trim().split(/\n/);
95
      tags = tags.filter(function(info) {
96
        info = info.split('-');
97
        return info.length == 1;
0 ignored issues
show
Best Practice introduced by
Comparing info.length to 1 using the == operator is not safe. Consider using === instead.
Loading history...
98
      });
99
100
      var versionTags = tags.filter(function(info) {
101
        return (/^v/.test(info[0]));
102
      });
103
104 2
      callback(undefined, versionTags[0] || tags[0]);
105
    });
106
  },
107
  log: function(filepath, pretty, callback) {
0 ignored issues
show
Unused Code introduced by
The parameter callback is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
108
	  var dateformat = 'format:"%d/%m/%Y"';
109
	  
110
	  // git log --date=format:"%d/%m/%Y" --pretty=format:"## %cd%n- %an <%ae>: %s (%H)" src/partials/atoms/link/index.html
111
	  var cmd = 'git log' + 
112
          (' --date='+dateformat) + 
113
          (pretty ? ' --pretty='+pretty : '') + 
114
	      (filepath ? ' '+filepath : '');
115
	  
116
	  return childProcess.execSync(cmd);
117
  }
118
};
119