-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
checkout.spec.js
59 lines (50 loc) · 1.97 KB
/
checkout.spec.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
53
54
55
56
57
58
59
import { lgPromise } from './common.js';
import assert from 'assert';
describe('git checkout', () => {
beforeEach(async () => {
const lg = await lgPromise;
const FS = lg.FS;
console.log('cwd', FS.cwd());
});
it('should discard changes to a path', async () => {
const lg = await lgPromise;
const FS = lg.FS;
FS.writeFile('/home/web_user/.gitconfig', '[user]\n' +
'name = Test User\n' +
'email = [email protected]');
FS.mkdir('test');
FS.chdir('test');
lg.callMain(['init', '.']);
FS.writeFile('test.txt', 'abcdef');
lg.callMain(['add', 'test.txt']);
lg.callMain(['commit', '-m', 'test commit']);
assert.equal(FS.readFile('test.txt', {encoding: 'utf8'}), 'abcdef');
FS.writeFile('test.txt', 'abcdefg');
lg.callMain(['checkout', '--', 'test.txt']);
lg.callMain(['status']);
assert.equal(FS.readFile('test.txt', {encoding: 'utf8'}), 'abcdef',
'expecting file content to be reverted');
});
it('should show error message if no path arguments are given', async () => {
const lg = await lgPromise;
const FS = lg.FS;
FS.writeFile('/home/web_user/.gitconfig', '[user]\n' +
'name = Test User\n' +
'email = [email protected]');
FS.mkdir('test99');
FS.chdir('test99');
lg.callMain(['init', '.']);
FS.writeFile('test.txt', 'abcdef');
lg.callMain(['add', 'test.txt']);
lg.callMain(['commit', '-m', 'test commit']);
assert.equal(FS.readFile('test.txt', {encoding: 'utf8'}), 'abcdef');
FS.writeFile('test.txt', 'abcdefg');
let errormessage;
try {
lg.callWithOutput(['checkout', '--']);
} catch (err) {
errormessage = err;
}
assert.equal(errormessage, '1: error: no paths specified');
});
});