@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/repository.ts
CHANGED
|
@@ -59,6 +59,13 @@ export interface RepositoryObject<T extends { [k: string]: any }> {
|
|
|
59
59
|
branch(): string;
|
|
60
60
|
|
|
61
61
|
tag(tag: string): string;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Moves the HEAD and the branch to a specific shaish (commit or tag)
|
|
65
|
+
* @param mode hard - discard changes
|
|
66
|
+
* @param shaish
|
|
67
|
+
*/
|
|
68
|
+
reset(mode?: "soft" | "hard", shaish?: string): void;
|
|
62
69
|
}
|
|
63
70
|
|
|
64
71
|
/**
|
|
@@ -84,12 +91,22 @@ export class Repository<T extends { [k: PropertyKey]: any }>
|
|
|
84
91
|
]);
|
|
85
92
|
|
|
86
93
|
this.commits = options.history?.commits ?? [];
|
|
94
|
+
|
|
95
|
+
if (options.history) {
|
|
96
|
+
const commit = this.commitAtHead();
|
|
97
|
+
if (!commit) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
this.moveTo(commit);
|
|
101
|
+
}
|
|
87
102
|
}
|
|
88
103
|
|
|
89
104
|
private readonly original: T;
|
|
90
105
|
|
|
91
106
|
data: T;
|
|
107
|
+
|
|
92
108
|
private observer: Observer<T>;
|
|
109
|
+
|
|
93
110
|
private readonly refs: Map<string, Reference>;
|
|
94
111
|
private readonly commits: Commit[];
|
|
95
112
|
|
|
@@ -104,6 +121,32 @@ export class Repository<T extends { [k: PropertyKey]: any }>
|
|
|
104
121
|
this.observer = observe(this.data);
|
|
105
122
|
}
|
|
106
123
|
|
|
124
|
+
reset(
|
|
125
|
+
mode: "soft" | "hard" | undefined = "hard",
|
|
126
|
+
shaish: string | undefined = REFS_HEAD_KEY,
|
|
127
|
+
): void {
|
|
128
|
+
if (mode === "hard") {
|
|
129
|
+
unobserve(this.data, this.observer);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const [commit] = shaishToCommit(shaish, this.refs, this.commits);
|
|
133
|
+
this.moveTo(commit);
|
|
134
|
+
|
|
135
|
+
const refs = refsAtCommit(this.refs, commit);
|
|
136
|
+
// reset only moves heads and not tags
|
|
137
|
+
const moveableRefs = refs.filter((r) =>
|
|
138
|
+
r.name.startsWith(headsRefPathPrefix),
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
for (const ref of moveableRefs) {
|
|
142
|
+
this.moveRef(ref.name, commit);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (mode === "hard") {
|
|
146
|
+
this.observer = observe(this.data);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
107
150
|
branch(): string {
|
|
108
151
|
const currentHeadRef = this.refs.get(REFS_HEAD_KEY);
|
|
109
152
|
if (!currentHeadRef) {
|
|
@@ -145,12 +188,12 @@ export class Repository<T extends { [k: PropertyKey]: any }>
|
|
|
145
188
|
const [commit, isRef, refKey] = shaishToCommit(
|
|
146
189
|
shaish,
|
|
147
190
|
this.refs,
|
|
148
|
-
this.commits
|
|
191
|
+
this.commits,
|
|
149
192
|
);
|
|
150
193
|
this.moveTo(commit);
|
|
151
194
|
this.moveRef(
|
|
152
195
|
REFS_HEAD_KEY,
|
|
153
|
-
isRef && refKey !== undefined ? refKey : commit
|
|
196
|
+
isRef && refKey !== undefined ? refKey : commit,
|
|
154
197
|
);
|
|
155
198
|
}
|
|
156
199
|
}
|
|
@@ -158,7 +201,7 @@ export class Repository<T extends { [k: PropertyKey]: any }>
|
|
|
158
201
|
async commit(
|
|
159
202
|
message: string,
|
|
160
203
|
author: string,
|
|
161
|
-
amend?: boolean
|
|
204
|
+
amend?: boolean,
|
|
162
205
|
): Promise<string> {
|
|
163
206
|
let parent = this.commitAtHead();
|
|
164
207
|
if (amend && !parent) {
|
|
@@ -196,7 +239,7 @@ export class Repository<T extends { [k: PropertyKey]: any }>
|
|
|
196
239
|
});
|
|
197
240
|
|
|
198
241
|
const treeHash = Buffer.from(
|
|
199
|
-
compressSync(strToU8(JSON.stringify(this.data)), { level: 6, mem: 8 })
|
|
242
|
+
compressSync(strToU8(JSON.stringify(this.data)), { level: 6, mem: 8 }),
|
|
200
243
|
).toString("base64");
|
|
201
244
|
const commit = {
|
|
202
245
|
hash: sha,
|
|
@@ -307,7 +350,7 @@ export class Repository<T extends { [k: PropertyKey]: any }>
|
|
|
307
350
|
throw new Error(
|
|
308
351
|
`fatal: source type (${
|
|
309
352
|
source instanceof Repository ? "Repository" : "History"
|
|
310
|
-
}) not implemented
|
|
353
|
+
}) not implemented`,
|
|
311
354
|
);
|
|
312
355
|
}
|
|
313
356
|
|
|
@@ -374,7 +417,7 @@ export class Repository<T extends { [k: PropertyKey]: any }>
|
|
|
374
417
|
throw new Error(`unreachable: HEAD not present`);
|
|
375
418
|
}
|
|
376
419
|
throw new Error(
|
|
377
|
-
`fatal: not a valid object name: '${getLastItem(headRef)}'
|
|
420
|
+
`fatal: not a valid object name: '${getLastItem(headRef)}'`,
|
|
378
421
|
);
|
|
379
422
|
}
|
|
380
423
|
this.refs.set(refKey, { name: name, value: headCommit.hash });
|
|
@@ -430,7 +473,7 @@ const traverseAndCollectChangelog = (commit: Commit, commitsList: Commit[]) => {
|
|
|
430
473
|
const mapPath = (
|
|
431
474
|
from: Commit,
|
|
432
475
|
to: Commit,
|
|
433
|
-
commits: Commit[]
|
|
476
|
+
commits: Commit[],
|
|
434
477
|
): [isAncestor: boolean] => {
|
|
435
478
|
let c: Commit | undefined = to;
|
|
436
479
|
while (c !== undefined) {
|
|
@@ -451,7 +494,7 @@ const mapPath = (
|
|
|
451
494
|
const commitAtRefIn = (
|
|
452
495
|
ref: string,
|
|
453
496
|
references: Map<string, Reference>,
|
|
454
|
-
commitsList: Commit[]
|
|
497
|
+
commitsList: Commit[],
|
|
455
498
|
) => {
|
|
456
499
|
const reference = references.get(ref);
|
|
457
500
|
if (!reference) {
|
|
@@ -477,6 +520,16 @@ const commitAtRefIn = (
|
|
|
477
520
|
return undefined;
|
|
478
521
|
};
|
|
479
522
|
|
|
523
|
+
const refsAtCommit = (references: Map<string, Reference>, commit: Commit) => {
|
|
524
|
+
const list: Array<Reference> = [];
|
|
525
|
+
for (const [name, ref] of references.entries()) {
|
|
526
|
+
if (ref.value === commit.hash) {
|
|
527
|
+
list.push(ref);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
return list;
|
|
531
|
+
};
|
|
532
|
+
|
|
480
533
|
/**
|
|
481
534
|
* Accepts a shaish expression (e.g. refs (branches, tags), commitSha) and returns
|
|
482
535
|
* - a commit of type Commit
|
|
@@ -486,7 +539,7 @@ const commitAtRefIn = (
|
|
|
486
539
|
const shaishToCommit = (
|
|
487
540
|
shaish: string,
|
|
488
541
|
references: Map<string, Reference>,
|
|
489
|
-
commitsList: Commit[]
|
|
542
|
+
commitsList: Commit[],
|
|
490
543
|
): [commit: Commit, isRef: boolean, ref: string | undefined] => {
|
|
491
544
|
let sha = shaish;
|
|
492
545
|
let isRef = false;
|
|
@@ -557,7 +610,7 @@ export const validateRef = (name: string, oneLevel: boolean = true) => {
|
|
|
557
610
|
* @param repository
|
|
558
611
|
*/
|
|
559
612
|
export const printChangeLog = <T extends { [k: string]: any }>(
|
|
560
|
-
repository: RepositoryObject<T
|
|
613
|
+
repository: RepositoryObject<T>,
|
|
561
614
|
) => {
|
|
562
615
|
console.log("----------------------------------------------------------");
|
|
563
616
|
console.log(`Changelog at ${repository.head()}`);
|
package/src/tag.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("cannot tag on an empty repo", async (t) => {
|
|
@@ -8,7 +8,7 @@ test("cannot tag on an empty repo", async (t) => {
|
|
|
8
8
|
() => {
|
|
9
9
|
repo.tag("v1.0.0");
|
|
10
10
|
},
|
|
11
|
-
{ message: `fatal: failed to resolve 'HEAD' as a valid ref.` }
|
|
11
|
+
{ message: `fatal: failed to resolve 'HEAD' as a valid ref.` },
|
|
12
12
|
);
|
|
13
13
|
});
|
|
14
14
|
|
|
@@ -21,10 +21,10 @@ test("can create simple tag pointing to HEAD", async (t) => {
|
|
|
21
21
|
const tagRef = repo.tag(tag);
|
|
22
22
|
|
|
23
23
|
let expectedRefKey = `refs/tags/${tag}`;
|
|
24
|
-
t.
|
|
25
|
-
t.
|
|
24
|
+
t.equal(tagRef, expectedRefKey);
|
|
25
|
+
t.equal(repo.ref(tagRef), commit, "tag is not pointing to expected commit");
|
|
26
26
|
const { refs } = repo.getHistory();
|
|
27
|
-
t.
|
|
27
|
+
t.ok(refs.has(expectedRefKey), "reference was not present in history");
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
test("cannot create tag with whitespace", async (t) => {
|
|
@@ -37,6 +37,6 @@ test("cannot create tag with whitespace", async (t) => {
|
|
|
37
37
|
() => {
|
|
38
38
|
repo.tag(tag);
|
|
39
39
|
},
|
|
40
|
-
{ message: `fatal: '${tag}' is not a valid tag name` }
|
|
40
|
+
{ message: `fatal: '${tag}' is not a valid tag name` },
|
|
41
41
|
);
|
|
42
42
|
});
|
package/src/test.utils.ts
CHANGED
|
@@ -2,24 +2,29 @@ import { v4 as uuid4 } from "uuid";
|
|
|
2
2
|
import { Repository, RepositoryObject } from "./repository";
|
|
3
3
|
import { Commit } from "./commit";
|
|
4
4
|
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
5
|
+
export type NestedObject = {
|
|
6
|
+
name?: string;
|
|
7
|
+
uuid?: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type ComplexObject = {
|
|
11
|
+
uuid?: string;
|
|
12
|
+
name?: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
nested: NestedObject[];
|
|
15
|
+
};
|
|
16
16
|
|
|
17
17
|
export const testAuthor = "User name <name@domain.com>";
|
|
18
18
|
|
|
19
19
|
export async function getBaseline(): Promise<
|
|
20
20
|
[RepositoryObject<ComplexObject>, ComplexObject]
|
|
21
21
|
> {
|
|
22
|
-
const co =
|
|
22
|
+
const co: ComplexObject = {
|
|
23
|
+
uuid: undefined,
|
|
24
|
+
name: undefined,
|
|
25
|
+
description: undefined,
|
|
26
|
+
nested: [],
|
|
27
|
+
};
|
|
23
28
|
const repo = new Repository(co, {});
|
|
24
29
|
return [repo, co];
|
|
25
30
|
}
|
|
@@ -33,7 +38,7 @@ export function updateHeaderData(wrapped: ComplexObject) {
|
|
|
33
38
|
}
|
|
34
39
|
|
|
35
40
|
export function addOneStep(wrapped: ComplexObject) {
|
|
36
|
-
const pe =
|
|
41
|
+
const pe: NestedObject = {};
|
|
37
42
|
pe.uuid = uuid4();
|
|
38
43
|
pe.name = "first name";
|
|
39
44
|
|
package/src/utils.test.ts
CHANGED
|
@@ -1,40 +1,46 @@
|
|
|
1
|
-
import test from "
|
|
1
|
+
import { test } from "tap";
|
|
2
2
|
import { cleanAuthor } from "./utils";
|
|
3
3
|
|
|
4
4
|
test("author <email@domain.info>", (t) => {
|
|
5
5
|
const [name, email] = cleanAuthor("author <email@domain.info>");
|
|
6
|
-
t.
|
|
7
|
-
t.
|
|
6
|
+
t.equal(name, "author");
|
|
7
|
+
t.equal(email, "email@domain.info");
|
|
8
|
+
t.end();
|
|
8
9
|
});
|
|
9
10
|
|
|
10
11
|
test("author with space <email@domain.info>", (t) => {
|
|
11
12
|
const [name, email] = cleanAuthor("author with space <email@domain.info>");
|
|
12
|
-
t.
|
|
13
|
-
t.
|
|
13
|
+
t.equal(name, "author with space");
|
|
14
|
+
t.equal(email, "email@domain.info");
|
|
15
|
+
t.end();
|
|
14
16
|
});
|
|
15
17
|
|
|
16
18
|
test("author @handle", (t) => {
|
|
17
19
|
const [name, email] = cleanAuthor("author @handle");
|
|
18
|
-
t.
|
|
19
|
-
t.
|
|
20
|
+
t.equal(name, "author");
|
|
21
|
+
t.equal(email, "@handle");
|
|
22
|
+
t.end();
|
|
20
23
|
});
|
|
21
24
|
|
|
22
25
|
test("author with space @handle", (t) => {
|
|
23
26
|
const [name, email] = cleanAuthor("author with space @handle");
|
|
24
|
-
t.
|
|
25
|
-
t.
|
|
27
|
+
t.equal(name, "author with space");
|
|
28
|
+
t.equal(email, "@handle");
|
|
29
|
+
t.end();
|
|
26
30
|
});
|
|
27
31
|
|
|
28
32
|
test("email@domain.info", (t) => {
|
|
29
33
|
const [name, email] = cleanAuthor("email@domain.info");
|
|
30
|
-
t.
|
|
31
|
-
t.
|
|
34
|
+
t.equal(name, "");
|
|
35
|
+
t.equal(email, "email@domain.info");
|
|
36
|
+
t.end();
|
|
32
37
|
});
|
|
33
38
|
|
|
34
39
|
test("@handle", (t) => {
|
|
35
40
|
const [name, email] = cleanAuthor("@handle");
|
|
36
|
-
t.
|
|
37
|
-
t.
|
|
41
|
+
t.equal(name, "@handle");
|
|
42
|
+
t.equal(email, "");
|
|
43
|
+
t.end();
|
|
38
44
|
});
|
|
39
45
|
|
|
40
46
|
test("empty author", (t) => {
|
|
@@ -42,6 +48,7 @@ test("empty author", (t) => {
|
|
|
42
48
|
() => {
|
|
43
49
|
cleanAuthor("");
|
|
44
50
|
},
|
|
45
|
-
{ message: "author not provided" }
|
|
51
|
+
{ message: "author not provided" },
|
|
46
52
|
);
|
|
53
|
+
t.end();
|
|
47
54
|
});
|