Repository navigation
Expand file tree
/
Copy pathbranch-set.test.js
More file actions
96 lines (76 loc) · 3.6 KB
/
Copy pathbranch-set.test.js
File metadata and controls
96 lines (76 loc) · 3.6 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
import BranchSet from '../../lib/models/branch-set';
import Branch, {nullBranch} from '../../lib/models/branch';
describe('BranchSet', function() {
it('earmarks HEAD', function() {
const bs = new BranchSet();
bs.add(new Branch('foo'));
bs.add(new Branch('bar', Branch.createRemoteTracking('upstream/bar', 'upstream', 'refs/heads/bar')));
const current = new Branch('currentBranch', nullBranch, nullBranch, true);
bs.add(current);
assert.strictEqual(current, bs.getHeadBranch());
});
it('returns a nullBranch if no ref is HEAD', function() {
const bs = new BranchSet();
bs.add(new Branch('foo'));
bs.add(new Branch('bar', Branch.createRemoteTracking('upstream/bar', 'upstream', 'refs/heads/bar')));
assert.isFalse(bs.getHeadBranch().isPresent());
});
describe('getPullTargets() and getPushSources()', function() {
let bs, bar, baz, boo, sharedUpPush, sharedUp, sharedPush;
beforeEach(function() {
bs = new BranchSet();
// A branch with no upstream or push target
bs.add(new Branch('foo'));
// A branch with a consistent upstream and push
bar = new Branch('bar', Branch.createRemoteTracking('upstream/bar', 'upstream', 'refs/heads/bar'));
bs.add(bar);
// A branch with an upstream and push that use some weird-ass refspec
baz = new Branch('baz', Branch.createRemoteTracking('origin/baz', 'origin', 'refs/heads/remotes/wat/boop'));
bs.add(baz);
// A branch with an upstream and push that differ
boo = new Branch(
'boo',
Branch.createRemoteTracking('upstream/boo', 'upstream', 'refs/heads/fetch-from-here'),
Branch.createRemoteTracking('origin/boo', 'origin', 'refs/heads/push-to-here'),
);
bs.add(boo);
// Branches that fetch and push to the same remote ref as other branches
sharedUpPush = new Branch(
'shared/up/push',
Branch.createRemoteTracking('upstream/shared/up/push', 'upstream', 'refs/heads/shared/up'),
Branch.createRemoteTracking('origin/shared/up/push', 'origin', 'refs/heads/shared/push'),
);
bs.add(sharedUpPush);
sharedUp = new Branch(
'shared/up',
Branch.createRemoteTracking('upstream/shared/up', 'upstream', 'refs/heads/shared/up'),
);
bs.add(sharedUp);
sharedPush = new Branch(
'shared/push',
Branch.createRemoteTracking('origin/shared/push', 'origin', 'refs/heads/shared/push'),
);
bs.add(sharedPush);
});
it('returns empty results for an unknown remote', function() {
assert.lengthOf(bs.getPullTargets('unknown', 'refs/heads/bar'), 0);
assert.lengthOf(bs.getPushSources('unknown', 'refs/heads/bar'), 0);
});
it('returns empty results for an unknown ref', function() {
assert.lengthOf(bs.getPullTargets('upstream', 'refs/heads/unknown'), 0);
assert.lengthOf(bs.getPushSources('origin', 'refs/heads/unknown'), 0);
});
it('locates branches that fetch from a remote ref', function() {
assert.deepEqual(bs.getPullTargets('upstream', 'refs/heads/bar'), [bar]);
});
it('locates multiple branches that fetch from the same ref', function() {
assert.sameMembers(bs.getPullTargets('upstream', 'refs/heads/shared/up'), [sharedUpPush, sharedUp]);
});
it('locates branches that push to a remote ref', function() {
assert.deepEqual(bs.getPushSources('origin', 'refs/heads/push-to-here'), [boo]);
});
it('locates multiple branches that push to the same ref', function() {
assert.sameMembers(bs.getPushSources('origin', 'refs/heads/shared/push'), [sharedUpPush, sharedPush]);
});
});
});