This repository was archived by the owner on Dec 15, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathgit.js
More file actions
119 lines (91 loc) · 2.82 KB
/
Copy pathgit.js
File metadata and controls
119 lines (91 loc) · 2.82 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/* jshint node:true */
'use strict';
var Repo = require('git-tools');
var RSVP = require('rsvp');
var RepoPrototype = Repo.prototype;
/**
* Add methods to the git-tools class, these should eventually be made into a PR
*/
RepoPrototype.currentTag = function(callback) {
var self = this;
this.exec("rev-parse", "HEAD", function(error, data) {
if (error) {
return callback(error);
}
// Look up the tag name using the current SHA
self.exec("name-rev", "--tags", "--name-only", data, function(error, data) {
var tagName = null;
if (error) {
return callback(error);
}
// Git outputs 'undefined' if the SHA does not match a tag (not JS related)
if (data !== 'undefined') {
// Annotated tags will be appendded with the distance from the tag using
// ~ notation, in which case sha^0 is distance zero
var match = data.match(/(.*?)(\^0|~\d+)?$/);
if (!match[2] || match[2] === '^0') {
tagName = match[1];
}
}
callback(null, tagName);
});
});
};
RepoPrototype.createTag = function(tagName, message, callback) {
if (typeof message === 'function') {
callback = message;
message = null;
}
// Create an annotated tag if a message is supplied
if (message) {
this.exec("tag", "--annotate", "--message", message, tagName, callback);
} else {
this.exec("tag", tagName, callback);
}
};
RepoPrototype.pushTags = function(remote, callback) {
this.exec("push", remote, "--tags", callback);
};
RepoPrototype.push = function(remote, treeish, callback) {
this.exec("push", remote, treeish, callback);
};
RepoPrototype.status = function(callback) {
this.exec("status", "--porcelain", callback);
};
RepoPrototype.addAll = function(callback) {
this.exec("add", "--all", callback);
};
RepoPrototype.commit = function(message, callback) {
this.exec("commit", "--message", message, callback);
};
RepoPrototype.commitAll = function(message, callback) {
this.exec("commit", "--all", "--message", message, callback);
};
/**
* Create promise-aware wrapper for git-tools class
*/
function DenodeifiedRepo(path) {
this._repo = new Repo(path);
}
DenodeifiedRepo.toString = function() {
return 'DenodeifiedRepo';
};
var DenodeifiedRepoPrototype = DenodeifiedRepo.prototype = Object.create(null);
DenodeifiedRepoPrototype.constructor = DenodeifiedRepo;
// Cherry-pick only the methods needed, since some are only used internally (e.g. `exec`)
var repoMethods = [
'tags',
'status',
'currentBranch',
'currentTag',
'createTag',
'commitAll',
'push'
];
repoMethods.forEach(function(methodName) {
var func = RSVP.denodeify(RepoPrototype[methodName]);
DenodeifiedRepoPrototype[methodName] = function denodeifiedMethod() {
return func.apply(this._repo, arguments);
};
});
module.exports = DenodeifiedRepo;