-
Notifications
You must be signed in to change notification settings - Fork 642
Expand file tree
/
Copy pathspec.git-parser.js
More file actions
111 lines (104 loc) · 4.63 KB
/
spec.git-parser.js
File metadata and controls
111 lines (104 loc) · 4.63 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
const expect = require('expect.js');
const path = require('path');
const gitParser = require('../src/git-parser');
describe('git-parser status', () => {
describe('with submodules', () => {
it('should mark submodules with untracked files as dirty', () => {
const text = `## dirty-submodules
m amodule`;
const res = gitParser.parseGitStatus(text);
expect(res.files['amodule'].dirty).to.be(true);
});
it('should mark submodules with modified contents as dirty', () => {
const text = `## dirty-submodules
? amodule`;
const res = gitParser.parseGitStatus(text);
expect(res.files['amodule'].dirty).to.be(true);
});
it('should not mark submodules with a diferent HEAD as dirty', () => {
const text = `## dirty-submodules
M amodule`;
const res = gitParser.parseGitStatus(text);
expect(res.files['amodule'].dirty).to.be(false);
});
it('should not mark normal changes as dirty', () => {
const text = `## dirty-submodules
xA afile`;
const res = gitParser.parseGitStatus(text);
expect(res.files['amodule'].dirty).to.be(false);
});
});
});
describe('git-parser stash show', () => {
it('should be possible to parse stashed show', () => {
const text = ' New Text Document (2).txt | 5 +++++\n 1 file changed, 5 insertions(+)\n';
const res = gitParser.parseGitStashShow(text);
expect(res).to.be.an('array');
expect(res.length).to.be(1);
expect(res[0].filename).to.be('New Text Document (2).txt');
});
});
describe('git-parse diff on big change', () => {
describe('git-parser parseGitLog', () => {
it('should work with branch name with ()', () => {
const refs = gitParser.parseGitLog('commit AAA BBB (HEAD, (test), fw(4rw), 5), ((, ()')[0].refs;
if(refs.length != 6) {
throw new Error('Failed to parse git log with branch name with ().');
}
});
it('should work with no branch name', () => {
const refs = gitParser.parseGitLog('commit AAA BBB')[0].refs;
if(refs.length != 0) {
throw new Error('Failed to parse git log without branches.');
}
});
});
});
describe('git-parser submodule', () => {
it('should work with empty string', () => {
const gitmodules = "";
const submodules = gitParser.parseGitSubmodule(gitmodules);
expect(submodules).to.be.an('object').and.to.be.empty();
});
it('should work with name, path and url', () => {
const gitmodules = '[submodule "test1"]\npath = /path/to/sub1\nurl = http://example1.com';
const submodules = gitParser.parseGitSubmodule(gitmodules);
expect(submodules.length).to.be(1);
expect(submodules[0].name).to.be('test1');
expect(submodules[0].path).to.be(path.join(path.sep, 'path', 'to', 'sub1'));
expect(submodules[0].url).to.be('http://example1.com');
});
it('should work with multiple name, path and url', () => {
const gitmodules = [
'[submodule "test1"]\npath = /path/to/sub1\nurl = http://example1.com',
'[submodule "test2"]\npath = /path/to/sub2\nurl = http://example2.com',
].join('\n');
const submodules = gitParser.parseGitSubmodule(gitmodules);
expect(submodules.length).to.be(2);
expect(submodules[0].name).to.be('test1');
expect(submodules[0].path).to.be(path.join(path.sep, 'path', 'to', 'sub1'));
expect(submodules[0].url).to.be('http://example1.com');
expect(submodules[1].name).to.be('test2');
expect(submodules[1].path).to.be(path.join(path.sep, 'path', 'to', 'sub2'));
expect(submodules[1].url).to.be('http://example2.com');
});
it('should work with multiple name, path, url, update, branch, fetchRecurseSubmodules and ignore', () => {
const gitmodules = [
'[submodule "test1"]\npath = /path/to/sub1\nurl = http://example1.com\nupdate = checkout\nbranch = master\nfetchRecurseSubmodules = true\nignore = all',
'[submodule "test2"]\n\npath ==/path/to/sub2\nurl= git://example2.com',
].join('\n');
const submodules = gitParser.parseGitSubmodule(gitmodules);
expect(submodules.length).to.be(2);
expect(submodules[0].name).to.be('test1');
expect(submodules[0].path).to.be(path.join(path.sep, 'path', 'to', 'sub1'));
expect(submodules[0].url).to.be('http://example1.com');
expect(submodules[0].update).to.be('checkout');
expect(submodules[0].branch).to.be('master');
expect(submodules[0].fetchRecurseSubmodules).to.be('true');
expect(submodules[0].ignore).to.be('all');
expect(submodules[1].name).to.be('test2');
expect(submodules[1].path).to.be(path.join('=', 'path', 'to', 'sub2'));
expect(submodules[1].url).to.be('http://example2.com');
expect(submodules[1].rawUrl).to.be('git://example2.com');
});
});