forked from petersalomonsen/wasm-git
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstashpop.spec.js
123 lines (113 loc) · 4.64 KB
/
stashpop.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
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
120
121
122
123
/*
Expected output with regular git (the difference is in the last status):
peter@MacBook-Air wgtest % echo "hei" > test.txt
peter@MacBook-Air wgtest % git add test.txt
peter@MacBook-Air wgtest % git commit -m "hei"
[master (root-commit) 6059cdd] hei
1 file changed, 1 insertion(+)
create mode 100644 test.txt
peter@MacBook-Air wgtest % git checkout -b testbranch
Switched to a new branch 'testbranch'
peter@MacBook-Air wgtest % echo "hei" > test2.txt
peter@MacBook-Air wgtest % git add test2.txt
peter@MacBook-Air wgtest % git commit -m "heia"
[testbranch 4892397] heia
1 file changed, 1 insertion(+)
create mode 100644 test2.txt
peter@MacBook-Air wgtest % echo "hei2" > test2.txt
peter@MacBook-Air wgtest % git checkout master
error: Your local changes to the following files would be overwritten by checkout:
test2.txt
Please commit your changes or stash them before you switch branches.
Aborting
peter@MacBook-Air wgtest % git stash
Saved working directory and index state WIP on testbranch: 4892397 heia
peter@MacBook-Air wgtest % git checkout master
Switched to branch 'master'
peter@MacBook-Air wgtest % git stash pop
CONFLICT (modify/delete): test2.txt deleted in Updated upstream and modified in Stashed changes. Version Stashed changes of test2.txt left in tree.
The stash entry is kept in case you need it again.
peter@MacBook-Air wgtest % git status --short
DU test2.txt
peter@MacBook-Air wgtest % git status
On branch master
Unmerged paths:
(use "git restore --staged <file>..." to unstage)
(use "git add/rm <file>..." as appropriate to mark resolution)
deleted by us: test2.txt
no changes added to commit (use "git add" and/or "git commit -a")
peter@MacBook-Air wgtest % git status --short
DU test2.txt
*/
describe('wasm-git-stash-pop', function () {
this.timeout(20000);
let worker;
const createWorker = async () => {
worker = new Worker(new URL('worker.js', import.meta.url), {type: 'module'});
await new Promise(resolve => {
worker.onmessage = msg => {
if (msg.data.ready) {
resolve(msg);
}
}
});
}
const callWorker = async (command, params) => {
return await new Promise(resolve => {
worker.onmessage = msg => resolve(msg.data);
worker.postMessage(Object.assign({
command: command
}, params));
});
};
const callWorkerWithArgs = async (command, ...args) => {
return await new Promise(resolve => {
worker.onmessage = msg => resolve(msg.data)
worker.postMessage({
command: command,
args: args
});
});
};
this.beforeAll(async () => {
await createWorker();
await callWorker('synclocal', {url: `${location.origin}/teststash.git`, newrepo: true });
});
this.afterAll(async () => {
assert.equal((await callWorker('deletelocal')).deleted, 'teststash.git');
worker.terminate();
});
it('should create repo pop and stash, and show conflict', async () => {
await callWorkerWithArgs('init', '.');
await callWorker(
'writefile', {
filename: 'test.txt',
contents: 'blabla'
});
await callWorkerWithArgs('add', 'test.txt');
await callWorkerWithArgs('commit', '-m', 'first commit');
await callWorkerWithArgs('checkout', '-b', 'testbranch');
await callWorker(
'writefile', {
filename: 'test2.txt',
contents: 'blabla'
});
await callWorkerWithArgs('add', 'test2.txt');
await callWorkerWithArgs('commit', '-m', 'second commit');
await callWorker(
'writefile', {
filename: 'test2.txt',
contents: 'blabla2'
});
assert.isTrue((await callWorkerWithArgs('checkout', 'master')).stderr.indexOf('1 conflict prevents checkout')>-1);
await callWorkerWithArgs('stash');
assert.equal((await callWorkerWithArgs('checkout', 'master')).stderr,'');
assert.equal((await callWorker('dir')).dircontents.findIndex(f => f==='test2.txt'), -1);
await callWorkerWithArgs('stash', 'pop');
assert.isTrue((await callWorker('dir')).dircontents.findIndex(f => f==='test2.txt')>-1);
// This part is different in libgit2 status from cmd line git
// assert.equal((await callWorker('status')).stdout, 'DU test2.txt');
console.log((await callWorker('status')).stdout);
assert.isTrue((await callWorker('status')).stdout.indexOf('conflict: a:test2.txt o:NULL t:test2.txt') >0 );
});
});