@dotinc/ogre 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.tap/processinfo/0799a6bd-022f-41d1-8be9-6338667041c0.json +245 -0
- package/.tap/processinfo/4cdc23d3-f7ce-4075-922f-722bf0d687fc.json +245 -0
- package/.tap/processinfo/6d907291-2f1e-4670-b04c-3a667271c352.json +245 -0
- package/.tap/processinfo/7dc6b1af-ac78-47bc-9b62-630e387e8755.json +245 -0
- package/.tap/processinfo/8c48e5e9-6eca-4afe-a7b5-04e26b765d29.json +241 -0
- package/.tap/processinfo/8ca695ae-d038-441a-b4ab-2a242d22d416.json +245 -0
- package/.tap/processinfo/98475c49-5ee5-4c2c-b8e2-85bd2af528c9.json +245 -0
- package/.tap/test-results/src/branch.test.ts.tap +40 -0
- package/.tap/test-results/src/checkout.test.ts.tap +52 -0
- package/.tap/test-results/src/commit.test.ts.tap +105 -0
- package/.tap/test-results/src/merge.test.ts.tap +16 -0
- package/.tap/test-results/src/repository.test.ts.tap +63 -0
- package/.tap/test-results/src/tag.test.ts.tap +19 -0
- package/.tap/test-results/src/utils.test.ts.tap +43 -0
- package/CHANGELOG.md +34 -1
- package/README.md +6 -4
- package/lib/commit.d.ts +0 -0
- package/lib/commit.js +0 -0
- package/lib/git2json.d.ts +0 -0
- package/lib/git2json.js +0 -0
- package/lib/hash.d.ts +0 -0
- package/lib/hash.js +0 -0
- package/lib/index.d.ts +0 -0
- package/lib/index.js +0 -0
- package/lib/interfaces.d.ts +0 -0
- package/lib/interfaces.js +0 -0
- package/lib/ref.d.ts +0 -0
- package/lib/ref.js +0 -0
- package/lib/repository.d.ts +7 -0
- package/lib/repository.js +32 -0
- package/lib/size.d.ts +0 -0
- package/lib/size.js +0 -0
- package/lib/test.utils.d.ts +9 -9
- package/lib/test.utils.js +8 -12
- package/lib/utils.d.ts +0 -0
- package/lib/utils.js +0 -0
- package/package.json +8 -20
- package/src/branch.test.ts +17 -17
- package/src/checkout.test.ts +29 -26
- package/src/commit.test.ts +60 -69
- package/src/merge.test.ts +13 -9
- package/src/repository.test.ts +160 -82
- package/src/repository.ts +63 -10
- package/src/tag.test.ts +6 -6
- package/src/test.utils.ts +18 -13
- package/src/utils.test.ts +21 -14
package/src/commit.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import test from "
|
|
1
|
+
import { test } from "tap";
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
addOneStep,
|
|
@@ -12,25 +12,22 @@ test("baseline with 1 commit and zero changelog entries", async (t) => {
|
|
|
12
12
|
const [repo] = await getBaseline();
|
|
13
13
|
|
|
14
14
|
const history = repo.getHistory();
|
|
15
|
-
t.
|
|
16
|
-
t.
|
|
15
|
+
t.equal(sumChanges(history.commits), 0, "has changelog entries");
|
|
16
|
+
t.equal(history.commits.length, 0, "incorrect # of commits");
|
|
17
17
|
});
|
|
18
18
|
|
|
19
19
|
test("head points to main", async (t) => {
|
|
20
20
|
const [repo] = await getBaseline();
|
|
21
21
|
|
|
22
|
-
t.
|
|
22
|
+
t.equal(repo.head(), "refs/heads/main", "head not pointing where it should");
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
test("no commit without changes", async (t) => {
|
|
26
26
|
const [repo] = await getBaseline();
|
|
27
27
|
|
|
28
|
-
await t.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
},
|
|
32
|
-
{ message: "no changes to commit" }
|
|
33
|
-
);
|
|
28
|
+
await t.rejects(repo.commit("baseline", testAuthor), {
|
|
29
|
+
message: "no changes to commit",
|
|
30
|
+
});
|
|
34
31
|
});
|
|
35
32
|
|
|
36
33
|
test("no commit without changes after recent commit", async (t) => {
|
|
@@ -38,12 +35,9 @@ test("no commit without changes after recent commit", async (t) => {
|
|
|
38
35
|
repo.data.name = "new name";
|
|
39
36
|
await repo.commit("baseline", testAuthor);
|
|
40
37
|
|
|
41
|
-
await t.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
},
|
|
45
|
-
{ message: "no changes to commit" }
|
|
46
|
-
);
|
|
38
|
+
await t.rejects(repo.commit("baseline", testAuthor), {
|
|
39
|
+
message: "no changes to commit",
|
|
40
|
+
});
|
|
47
41
|
});
|
|
48
42
|
|
|
49
43
|
test("treeHash of commit is matching content", async (t) => {
|
|
@@ -51,7 +45,7 @@ test("treeHash of commit is matching content", async (t) => {
|
|
|
51
45
|
repo.data.name = "new name";
|
|
52
46
|
await repo.commit("baseline", testAuthor);
|
|
53
47
|
const { commits } = repo.getHistory();
|
|
54
|
-
t.
|
|
48
|
+
t.equal(commits.length, 1);
|
|
55
49
|
t.not(commits[0].tree, "", "tree hash mismatch");
|
|
56
50
|
});
|
|
57
51
|
|
|
@@ -59,12 +53,9 @@ test("no commit --amend without commit", async (t) => {
|
|
|
59
53
|
const [repo] = await getBaseline();
|
|
60
54
|
repo.data.name = "new name";
|
|
61
55
|
|
|
62
|
-
await t.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
},
|
|
66
|
-
{ message: "no commit to amend" }
|
|
67
|
-
);
|
|
56
|
+
await t.rejects(repo.commit("baseline", testAuthor, true), {
|
|
57
|
+
message: "no commit to amend",
|
|
58
|
+
});
|
|
68
59
|
});
|
|
69
60
|
|
|
70
61
|
test("main moves to recent commit", async (t) => {
|
|
@@ -72,10 +63,10 @@ test("main moves to recent commit", async (t) => {
|
|
|
72
63
|
repo.data.name = "new name";
|
|
73
64
|
const hash = await repo.commit("baseline", testAuthor);
|
|
74
65
|
|
|
75
|
-
t.
|
|
66
|
+
t.equal(
|
|
76
67
|
repo.ref("refs/heads/main"),
|
|
77
68
|
hash,
|
|
78
|
-
"head does not point to recent commit"
|
|
69
|
+
"head does not point to recent commit",
|
|
79
70
|
);
|
|
80
71
|
});
|
|
81
72
|
|
|
@@ -85,8 +76,8 @@ test("two commits with 3 changes", async (t) => {
|
|
|
85
76
|
await repo.commit("header data", testAuthor);
|
|
86
77
|
|
|
87
78
|
const history = repo.getHistory();
|
|
88
|
-
t.
|
|
89
|
-
t.
|
|
79
|
+
t.equal(sumChanges(history.commits), 3, "incorrect # of changelog entries");
|
|
80
|
+
t.equal(history.commits.length, 1, "incorrect # of commits");
|
|
90
81
|
});
|
|
91
82
|
|
|
92
83
|
test("array push double-change, 6 changes, 3 commits", async (t) => {
|
|
@@ -99,17 +90,17 @@ test("array push double-change, 6 changes, 3 commits", async (t) => {
|
|
|
99
90
|
await repo.commit("first step", testAuthor);
|
|
100
91
|
|
|
101
92
|
const history = repo.getHistory();
|
|
102
|
-
t.
|
|
103
|
-
t.
|
|
104
|
-
t.
|
|
93
|
+
t.equal(sumChanges(history.commits), 4, "incorrect # of changelog entries");
|
|
94
|
+
t.equal(history.commits.length, 2, "incorrect # of commits");
|
|
95
|
+
t.equal(
|
|
105
96
|
history.commits[0].changes.length,
|
|
106
97
|
3,
|
|
107
|
-
"#incorrect # of changes in commit#1"
|
|
98
|
+
"#incorrect # of changes in commit#1",
|
|
108
99
|
);
|
|
109
|
-
t.
|
|
100
|
+
t.equal(
|
|
110
101
|
history.commits[1].changes.length,
|
|
111
102
|
1,
|
|
112
|
-
"#incorrect # of changes in commit#2"
|
|
103
|
+
"#incorrect # of changes in commit#2",
|
|
113
104
|
);
|
|
114
105
|
});
|
|
115
106
|
|
|
@@ -119,21 +110,21 @@ test("all refs OK, when committing on new branch while main is empty main", asyn
|
|
|
119
110
|
repo.data.name = "new name";
|
|
120
111
|
const commit = await repo.commit("simple change", testAuthor);
|
|
121
112
|
|
|
122
|
-
t.
|
|
113
|
+
t.equal(
|
|
123
114
|
repo.ref("refs/heads/main"),
|
|
124
115
|
undefined,
|
|
125
|
-
"main should not point to a commit"
|
|
116
|
+
"main should not point to a commit",
|
|
126
117
|
);
|
|
127
|
-
t.
|
|
118
|
+
t.equal(
|
|
128
119
|
repo.ref("refs/heads/new_feature"),
|
|
129
120
|
commit,
|
|
130
|
-
"new_feature should point to last commit"
|
|
121
|
+
"new_feature should point to last commit",
|
|
131
122
|
);
|
|
132
|
-
t.
|
|
133
|
-
t.
|
|
123
|
+
t.equal(repo.branch(), "new_feature", "branch should now be visible");
|
|
124
|
+
t.equal(
|
|
134
125
|
repo.head(),
|
|
135
126
|
"refs/heads/new_feature",
|
|
136
|
-
"HEAD is pointing to wrong branch"
|
|
127
|
+
"HEAD is pointing to wrong branch",
|
|
137
128
|
);
|
|
138
129
|
});
|
|
139
130
|
|
|
@@ -145,25 +136,25 @@ test("commit --amend changes hash on content change", async (t) => {
|
|
|
145
136
|
const changedHash = await repo.commit(
|
|
146
137
|
"name and description change",
|
|
147
138
|
testAuthor,
|
|
148
|
-
true
|
|
139
|
+
true,
|
|
149
140
|
);
|
|
150
141
|
t.not(changedHash, commitToAmend, "hash should have changed");
|
|
151
142
|
const history = repo.getHistory();
|
|
152
|
-
t.
|
|
143
|
+
t.equal(history.commits.length, 1, "wrong # of commits");
|
|
153
144
|
// @ts-ignore
|
|
154
|
-
t.
|
|
145
|
+
t.equal(
|
|
155
146
|
sumChanges(history.commits),
|
|
156
147
|
2,
|
|
157
148
|
`wrong # of changes: ${JSON.stringify(
|
|
158
|
-
history.commits.flatMap((c) => c.changes)
|
|
159
|
-
)}
|
|
149
|
+
history.commits.flatMap((c) => c.changes),
|
|
150
|
+
)}`,
|
|
160
151
|
);
|
|
161
|
-
t.
|
|
162
|
-
t.
|
|
163
|
-
t.
|
|
152
|
+
t.equal(repo.head(), "refs/heads/main", "HEAD is not pointing to main");
|
|
153
|
+
t.equal(repo.branch(), "main", "we are on the wrong branch");
|
|
154
|
+
t.equal(
|
|
164
155
|
repo.ref("refs/heads/main"),
|
|
165
156
|
changedHash,
|
|
166
|
-
"main should point to changed commit hash"
|
|
157
|
+
"main should point to changed commit hash",
|
|
167
158
|
);
|
|
168
159
|
});
|
|
169
160
|
|
|
@@ -177,14 +168,14 @@ test("commit --amend changes hash on message change", async (t) => {
|
|
|
177
168
|
|
|
178
169
|
t.not(changedHash, commitToAmend, "hash should have changed");
|
|
179
170
|
const history = repo.getHistory();
|
|
180
|
-
t.
|
|
181
|
-
t.
|
|
182
|
-
t.
|
|
183
|
-
t.
|
|
184
|
-
t.
|
|
171
|
+
t.equal(history.commits.length, 1, "wrong # of commits");
|
|
172
|
+
t.equal(sumChanges(history.commits), 1, "wrong # of changes");
|
|
173
|
+
t.equal(repo.head(), "refs/heads/main", "HEAD is not pointing to main");
|
|
174
|
+
t.equal(repo.branch(), "main", "we are on the wrong branch");
|
|
175
|
+
t.equal(
|
|
185
176
|
repo.ref("refs/heads/main"),
|
|
186
177
|
changedHash,
|
|
187
|
-
"main should point to changed commit hash"
|
|
178
|
+
"main should point to changed commit hash",
|
|
188
179
|
);
|
|
189
180
|
});
|
|
190
181
|
|
|
@@ -198,17 +189,17 @@ test("commit at detached HEAD does not affect main, but moves head", async (t) =
|
|
|
198
189
|
const last = await repo.commit("desc change", testAuthor);
|
|
199
190
|
|
|
200
191
|
repo.checkout(commit);
|
|
201
|
-
t.
|
|
202
|
-
t.
|
|
203
|
-
t.
|
|
192
|
+
t.equal(repo.head(), commit, "HEAD did not move to commit");
|
|
193
|
+
t.equal(repo.branch(), "HEAD", "repo is not in detached state");
|
|
194
|
+
t.matchOnly(v1, repo.data, "object state does not match");
|
|
204
195
|
|
|
205
196
|
repo.data.description = "a different description";
|
|
206
197
|
const commitOnDetached = await repo.commit("msg", testAuthor);
|
|
207
|
-
t.
|
|
208
|
-
t.
|
|
198
|
+
t.equal(repo.head(), commitOnDetached, "HEAD did not move to commit");
|
|
199
|
+
t.equal(
|
|
209
200
|
repo.ref("refs/heads/main"),
|
|
210
201
|
last,
|
|
211
|
-
"main branch did not stay at last commit"
|
|
202
|
+
"main branch did not stay at last commit",
|
|
212
203
|
);
|
|
213
204
|
});
|
|
214
205
|
|
|
@@ -224,10 +215,10 @@ test("commit at detached HEAD saved to a branch", async (t) => {
|
|
|
224
215
|
const commitOnDetached = await repo.commit("msg", testAuthor);
|
|
225
216
|
|
|
226
217
|
const savepointRef = repo.createBranch("savepoint");
|
|
227
|
-
t.
|
|
218
|
+
t.equal(
|
|
228
219
|
repo.ref(savepointRef),
|
|
229
220
|
commitOnDetached,
|
|
230
|
-
"savepoint branch should point to last detached commit"
|
|
221
|
+
"savepoint branch should point to last detached commit",
|
|
231
222
|
);
|
|
232
223
|
});
|
|
233
224
|
|
|
@@ -241,13 +232,13 @@ test("commit --amend changes hash on message change even in detached HEAD", asyn
|
|
|
241
232
|
const changedHash = await repo.commit("initial setup", testAuthor, true);
|
|
242
233
|
t.not(changedHash, commitToAmend, "hash should have changed");
|
|
243
234
|
const history = repo.getHistory();
|
|
244
|
-
t.
|
|
245
|
-
t.
|
|
246
|
-
t.
|
|
247
|
-
t.
|
|
248
|
-
t.
|
|
235
|
+
t.equal(history.commits.length, 1, "wrong # of commits");
|
|
236
|
+
t.equal(sumChanges(history.commits), 1, "wrong # of changes");
|
|
237
|
+
t.equal(repo.branch(), "HEAD", "not in detached state");
|
|
238
|
+
t.equal(repo.head(), changedHash, "HEAD is not pointing to detached commit");
|
|
239
|
+
t.equal(
|
|
249
240
|
repo.ref("refs/heads/main"),
|
|
250
241
|
descCommit,
|
|
251
|
-
"main should point to changed commit hash"
|
|
242
|
+
"main should point to changed commit hash",
|
|
252
243
|
);
|
|
253
244
|
});
|
package/src/merge.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import test from "
|
|
1
|
+
import { test } from "tap";
|
|
2
2
|
import { getBaseline, testAuthor } from "./test.utils";
|
|
3
3
|
|
|
4
4
|
test("merge with no commit fails", async (t) => {
|
|
@@ -12,7 +12,7 @@ test("merge with no commit fails", async (t) => {
|
|
|
12
12
|
() => {
|
|
13
13
|
repo.merge("new_feature");
|
|
14
14
|
},
|
|
15
|
-
{ message: "already up to date" }
|
|
15
|
+
{ message: "already up to date" },
|
|
16
16
|
);
|
|
17
17
|
});
|
|
18
18
|
|
|
@@ -25,11 +25,15 @@ test("merge fast-forward", async (t) => {
|
|
|
25
25
|
repo.checkout("new_branch", true);
|
|
26
26
|
repo.data.name = "another name";
|
|
27
27
|
const minorHash = await repo.commit("minor change", testAuthor);
|
|
28
|
-
t.
|
|
29
|
-
|
|
28
|
+
t.equal(
|
|
29
|
+
repo.head(),
|
|
30
|
+
"refs/heads/new_branch",
|
|
31
|
+
"HEAD not pointing to new_branch",
|
|
32
|
+
);
|
|
33
|
+
t.equal(
|
|
30
34
|
repo.ref("refs/heads/new_branch"),
|
|
31
35
|
minorHash,
|
|
32
|
-
"branch did not move to new commit"
|
|
36
|
+
"branch did not move to new commit",
|
|
33
37
|
);
|
|
34
38
|
|
|
35
39
|
// go to destination branch
|
|
@@ -38,11 +42,11 @@ test("merge fast-forward", async (t) => {
|
|
|
38
42
|
const headRef = repo.head();
|
|
39
43
|
const refHash = repo.ref(headRef);
|
|
40
44
|
|
|
41
|
-
t.
|
|
42
|
-
t.
|
|
43
|
-
t.
|
|
45
|
+
t.equal(mergeHash, minorHash, "did not fast-forward to expected commit");
|
|
46
|
+
t.equal(refHash, mergeHash, `master is not at expected commit`);
|
|
47
|
+
t.equal(
|
|
44
48
|
repo.getHistory().commits.length,
|
|
45
49
|
masterCommitCount + 1,
|
|
46
|
-
"fast-forward failed, superfluous commit detected"
|
|
50
|
+
"fast-forward failed, superfluous commit detected",
|
|
47
51
|
);
|
|
48
52
|
});
|
package/src/repository.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import test from "
|
|
1
|
+
import { test } from "tap";
|
|
2
2
|
|
|
3
3
|
import { Repository } from "./repository";
|
|
4
4
|
import {
|
|
@@ -9,84 +9,7 @@ import {
|
|
|
9
9
|
testAuthor,
|
|
10
10
|
updateHeaderData,
|
|
11
11
|
} from "./test.utils";
|
|
12
|
-
|
|
13
|
-
test("reconstruction", async (t) => {
|
|
14
|
-
const [repo, wrapped] = await getBaseline();
|
|
15
|
-
|
|
16
|
-
let changeEntries = updateHeaderData(wrapped);
|
|
17
|
-
await repo.commit("header data", testAuthor);
|
|
18
|
-
|
|
19
|
-
changeEntries += addOneNested(wrapped);
|
|
20
|
-
const firstStep = await repo.commit("first step", testAuthor);
|
|
21
|
-
|
|
22
|
-
const history = repo.getHistory();
|
|
23
|
-
t.is(repo.head(), "refs/heads/main", "HEAD is wrong");
|
|
24
|
-
t.is(
|
|
25
|
-
repo.ref("refs/heads/main"),
|
|
26
|
-
firstStep,
|
|
27
|
-
"main is pointing at wrong commit"
|
|
28
|
-
);
|
|
29
|
-
t.is(history.commits.length, 2, "incorrect # of commits");
|
|
30
|
-
|
|
31
|
-
// start reconstruction
|
|
32
|
-
const p = new ComplexObject();
|
|
33
|
-
const repo2 = new Repository(p, { history });
|
|
34
|
-
|
|
35
|
-
const history2 = repo2.getHistory();
|
|
36
|
-
t.is(history2.commits.length, 2, "incorrect # of commits");
|
|
37
|
-
t.is(
|
|
38
|
-
sumChanges(history2.commits),
|
|
39
|
-
changeEntries,
|
|
40
|
-
"incorrect # of changelog entries"
|
|
41
|
-
);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test("reconstruct with 2 commits", async (t) => {
|
|
45
|
-
const [repo, wrapped] = await getBaseline();
|
|
46
|
-
|
|
47
|
-
let changeEntries = updateHeaderData(wrapped);
|
|
48
|
-
await repo.commit("header data", testAuthor);
|
|
49
|
-
|
|
50
|
-
addOneNested(wrapped);
|
|
51
|
-
changeEntries++;
|
|
52
|
-
const first = await repo.commit("first nested", testAuthor);
|
|
53
|
-
|
|
54
|
-
t.is(repo.ref("refs/heads/main"), first, "main is pointing at wrong commit");
|
|
55
|
-
|
|
56
|
-
addOneNested(wrapped);
|
|
57
|
-
changeEntries++;
|
|
58
|
-
|
|
59
|
-
const second = await repo.commit("second nested", testAuthor);
|
|
60
|
-
|
|
61
|
-
const history = repo.getHistory();
|
|
62
|
-
|
|
63
|
-
t.is(repo.ref("refs/heads/main"), second, "main is pointing at wrong commit");
|
|
64
|
-
t.is(history.commits.length, 3, "incorrect # of commits");
|
|
65
|
-
|
|
66
|
-
// start reconstruction
|
|
67
|
-
const p = new ComplexObject();
|
|
68
|
-
const repo2 = new Repository(p, { history });
|
|
69
|
-
|
|
70
|
-
const history2 = repo2.getHistory();
|
|
71
|
-
t.is(history2.commits.length, 3, "incorrect # of commits");
|
|
72
|
-
t.is(
|
|
73
|
-
sumChanges(history2.commits),
|
|
74
|
-
changeEntries,
|
|
75
|
-
"incorrect # of changelog entries"
|
|
76
|
-
);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
test("history contains HEAD ref", async (t) => {
|
|
80
|
-
const [repo] = await getBaseline();
|
|
81
|
-
|
|
82
|
-
t.is(repo.head(), "refs/heads/main");
|
|
83
|
-
|
|
84
|
-
const history = repo.getHistory();
|
|
85
|
-
let headRef = history.refs.get("HEAD");
|
|
86
|
-
t.not(headRef, undefined);
|
|
87
|
-
t.is(headRef!.name, "HEAD");
|
|
88
|
-
t.is(headRef!.value, "ref: refs/heads/main");
|
|
89
|
-
});
|
|
12
|
+
import { History, Reference } from "./interfaces";
|
|
90
13
|
|
|
91
14
|
test("diff is ok", async (t) => {
|
|
92
15
|
const [repo, obj] = await getBaseline();
|
|
@@ -97,16 +20,171 @@ test("diff is ok", async (t) => {
|
|
|
97
20
|
let changeEntries = addOneNested(obj);
|
|
98
21
|
const first = await repo.commit("first nested", testAuthor);
|
|
99
22
|
|
|
100
|
-
t.
|
|
23
|
+
t.equal(
|
|
24
|
+
repo.ref("refs/heads/main"),
|
|
25
|
+
first,
|
|
26
|
+
"main is pointing at wrong commit",
|
|
27
|
+
);
|
|
101
28
|
|
|
102
29
|
changeEntries += addOneNested(obj);
|
|
103
30
|
|
|
104
31
|
const second = await repo.commit("second nested", testAuthor);
|
|
105
32
|
|
|
106
33
|
const diff = repo.diff(zeroth);
|
|
107
|
-
t.
|
|
34
|
+
t.equal(
|
|
108
35
|
diff.length,
|
|
109
36
|
changeEntries,
|
|
110
|
-
`invalid # of change entries: ${JSON.stringify(diff)}
|
|
37
|
+
`invalid # of change entries: ${JSON.stringify(diff)}`,
|
|
111
38
|
);
|
|
112
39
|
});
|
|
40
|
+
|
|
41
|
+
test("restore", async (t) => {
|
|
42
|
+
t.test("history check", async (t) => {
|
|
43
|
+
const [repo, wrapped] = await getBaseline();
|
|
44
|
+
|
|
45
|
+
let changeEntries = updateHeaderData(wrapped);
|
|
46
|
+
await repo.commit("header data", testAuthor);
|
|
47
|
+
|
|
48
|
+
changeEntries += addOneNested(wrapped);
|
|
49
|
+
const firstStep = await repo.commit("first step", testAuthor);
|
|
50
|
+
|
|
51
|
+
const history = repo.getHistory();
|
|
52
|
+
t.equal(repo.head(), "refs/heads/main", "HEAD is wrong");
|
|
53
|
+
t.equal(
|
|
54
|
+
repo.ref("refs/heads/main"),
|
|
55
|
+
firstStep,
|
|
56
|
+
"main is pointing at wrong commit",
|
|
57
|
+
);
|
|
58
|
+
t.equal(history.commits.length, 2, "incorrect # of commits");
|
|
59
|
+
|
|
60
|
+
// start reconstruction
|
|
61
|
+
const p = {};
|
|
62
|
+
const repo2 = new Repository(p, { history });
|
|
63
|
+
|
|
64
|
+
const history2 = repo2.getHistory();
|
|
65
|
+
t.equal(
|
|
66
|
+
history2.commits.length,
|
|
67
|
+
history.commits.length,
|
|
68
|
+
"incorrect # of commits",
|
|
69
|
+
);
|
|
70
|
+
t.equal(
|
|
71
|
+
sumChanges(history2.commits),
|
|
72
|
+
sumChanges(history.commits),
|
|
73
|
+
"incorrect # of changelog entries",
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
t.test("reconstruct with 2 commits", async (t) => {
|
|
78
|
+
const [repo, wrapped] = await getBaseline();
|
|
79
|
+
|
|
80
|
+
let changeEntries = updateHeaderData(wrapped);
|
|
81
|
+
await repo.commit("header data", testAuthor);
|
|
82
|
+
|
|
83
|
+
addOneNested(wrapped);
|
|
84
|
+
changeEntries++;
|
|
85
|
+
const first = await repo.commit("first nested", testAuthor);
|
|
86
|
+
|
|
87
|
+
t.equal(
|
|
88
|
+
repo.ref("refs/heads/main"),
|
|
89
|
+
first,
|
|
90
|
+
"main is pointing at wrong commit",
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
addOneNested(wrapped);
|
|
94
|
+
changeEntries++;
|
|
95
|
+
|
|
96
|
+
const second = await repo.commit("second nested", testAuthor);
|
|
97
|
+
|
|
98
|
+
const history = repo.getHistory();
|
|
99
|
+
|
|
100
|
+
t.equal(
|
|
101
|
+
repo.ref("refs/heads/main"),
|
|
102
|
+
second,
|
|
103
|
+
"main is pointing at wrong commit",
|
|
104
|
+
);
|
|
105
|
+
t.equal(history.commits.length, 3, "incorrect # of commits");
|
|
106
|
+
|
|
107
|
+
// start reconstruction
|
|
108
|
+
const p = {};
|
|
109
|
+
const repo2 = new Repository(p, { history });
|
|
110
|
+
|
|
111
|
+
const history2 = repo2.getHistory();
|
|
112
|
+
t.equal(
|
|
113
|
+
history2.commits.length,
|
|
114
|
+
history.commits.length,
|
|
115
|
+
"incorrect # of commits",
|
|
116
|
+
);
|
|
117
|
+
t.equal(
|
|
118
|
+
sumChanges(history2.commits),
|
|
119
|
+
sumChanges(history.commits),
|
|
120
|
+
"incorrect # of changelog entries",
|
|
121
|
+
);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test("restoring from history", async (t) => {
|
|
125
|
+
const [repo, obj] = await getBaseline();
|
|
126
|
+
updateHeaderData(obj);
|
|
127
|
+
await repo.commit("header data", testAuthor);
|
|
128
|
+
addOneNested(obj);
|
|
129
|
+
await repo.commit("first nested", testAuthor);
|
|
130
|
+
repo.tag("v0.1.0");
|
|
131
|
+
|
|
132
|
+
const history = repo.getHistory();
|
|
133
|
+
|
|
134
|
+
const obj2 = {};
|
|
135
|
+
// @ts-ignore
|
|
136
|
+
const repo2 = new Repository(obj2, { history });
|
|
137
|
+
|
|
138
|
+
t.matchOnly(obj, obj2, "restored object does not equal last version.");
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test("history", async (t) => {
|
|
143
|
+
t.test("history contains HEAD ref", async (t) => {
|
|
144
|
+
const [repo] = await getBaseline();
|
|
145
|
+
|
|
146
|
+
t.equal(repo.head(), "refs/heads/main");
|
|
147
|
+
|
|
148
|
+
const history = repo.getHistory();
|
|
149
|
+
let headRef = history.refs.get("HEAD");
|
|
150
|
+
t.not(headRef, undefined);
|
|
151
|
+
t.equal(headRef!.name, "HEAD");
|
|
152
|
+
t.equal(headRef!.value, "ref: refs/heads/main");
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
t.test("empty history unreachable HEAD", async (t) => {
|
|
156
|
+
const co: ComplexObject = { nested: [] };
|
|
157
|
+
t.throws(
|
|
158
|
+
() =>
|
|
159
|
+
new Repository(co, {
|
|
160
|
+
history: {
|
|
161
|
+
original: co,
|
|
162
|
+
refs: new Map<string, Reference>(),
|
|
163
|
+
commits: [],
|
|
164
|
+
} as History<ComplexObject>,
|
|
165
|
+
}),
|
|
166
|
+
{
|
|
167
|
+
message: "unreachable: 'HEAD' is not present",
|
|
168
|
+
},
|
|
169
|
+
);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
test("reset", async (t) => {
|
|
174
|
+
t.test("reset hard", async (t) => {
|
|
175
|
+
const [repo, co] = await getBaseline();
|
|
176
|
+
co.uuid = "asdf";
|
|
177
|
+
const hash = await repo.commit("baseline", testAuthor);
|
|
178
|
+
const h1 = repo.getHistory();
|
|
179
|
+
t.equal(h1.commits.length, 1);
|
|
180
|
+
// do changes
|
|
181
|
+
const changes = updateHeaderData(co);
|
|
182
|
+
const diff = repo.diff(hash);
|
|
183
|
+
t.equal(diff.length, changes, "wrong # of changes in diff");
|
|
184
|
+
|
|
185
|
+
// reset
|
|
186
|
+
repo.reset("hard");
|
|
187
|
+
const diff2 = repo.diff(hash);
|
|
188
|
+
t.equal(diff2.length, 0, "failed to reset");
|
|
189
|
+
});
|
|
190
|
+
});
|