-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit_utils.ts
57 lines (53 loc) · 1.57 KB
/
git_utils.ts
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
export async function gitAddA(git, repo) {
return git.statusMatrix(repo).then((status) => Promise.all(
status.map(([filepath, , worktreeStatus]) =>
// isomorphic-git may report a changed file as unmodified, so always add if not removing
worktreeStatus ? git.add({ ...repo, filepath }) : git.remove({ ...repo, filepath })
)
));
}
export async function getFileStateChanges (git, commitHash1, commitHash2, dir) {
return git.walkBeta1({
trees: [
git.TREE({ dir: dir, ref: commitHash1 }),
git.TREE({ dir: dir, ref: commitHash2 })
],
map: async function ([A, B]) {
// ignore directories
if (A.fullpath === '.') {
return
}
await A.populateStat()
if (A.type === 'tree') {
return
}
await B.populateStat()
if (B.type === 'tree') {
return
}
// generate ids
await A.populateHash()
await B.populateHash()
// determine modification type
let type = 'equal'
if (A.oid !== B.oid) {
type = 'modify'
}
if (A.oid === undefined) {
type = 'add'
}
if (B.oid === undefined) {
type = 'remove'
}
if (A.oid === undefined && B.oid === undefined) {
console.log('Something weird happened:')
console.log(A)
console.log(B)
}
return {
path: `/${A.fullpath}`,
type: type
}
}
})
}