-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathrefspec.js
52 lines (38 loc) · 1.35 KB
/
refspec.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
function Refspec(utils) {
return function (src, dst) {
var _this = this
, _priv = utils._createPrivate(_this);
_priv.srcRoot = (src !== null) && src.slice(-1) === "*" ? src.slice(0, -1) : src;
_priv.dstRoot = (dst !== null) && dst.slice(-1) === "*" ? dst.slice(0, -1) : dst;
utils._immutable(_this, {src: src, dst: dst})
.set('src')
.set('dst');
};
};
Refspec.prototype.matchesSrc = function (refName) {
var _this = this
, _priv = utils._getPrivate(_this);
if (refName.length <= _priv.srcRoot.length)
return false;
return refName.indexOf(_priv.srcRoot) === 0;
};
Refspec.prototype.matchesDst = function (refName) {
var _this = this
, _priv = utils._getPrivate(_this);
if (refName.length <= _priv.dstRoot.length)
return false;
return refName.indexOf(_priv.dstRoot) === 0;
};
Refspec.prototype.transformTo = function (refName) {
if (!this.matchesSrc(refName))
throw new Error('Ref doesn\'t match with src.');
return "" + this.dst.slice(0, -2) + refName.slice(this.src.length - 2);
};
Refspec.prototype.transformFrom = function (refName) {
if(!this.matchesDst(refName))
throw new Error('Ref doesn\'t match with dst.');
return "" + this.src.slice(0, -2) + refName.slice(this.dst.length - 2);
};
module.exports.all = function (Gitteh, utils) {
Gitteh.Refspec = Refspec(utils);
};