-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
55 lines (40 loc) · 1.17 KB
/
Copy pathindex.js
File metadata and controls
55 lines (40 loc) · 1.17 KB
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
import git from 'isomorphic-git'
import fs from 'bare-fs'
import createHyperbeeHttp from './hyperbee-http.js'
const { http, core } = await createHyperbeeHttp('./storage')
const url = 'http://hyperbee/repo'
// --- Push ---
const dir = './repo'
await git.init({ fs, dir, defaultBranch: 'main' })
await fs.promises.writeFile(`${dir}/README.md`, 'Hello World')
await git.add({ fs, dir, filepath: 'README.md' })
await git.commit({
fs,
dir,
message: 'Initial commit',
author: {
name: 'Cameron',
email: 'cameron@example.com',
},
})
await git.push({ fs, http, dir, url, ref: 'main' })
console.log('pushed to hyperbee')
// --- Clone ---
const cloneDir = './clone'
await fs.promises.mkdir(cloneDir, { recursive: true })
await git.clone({
fs,
http,
dir: cloneDir,
url,
ref: 'main',
singleBranch: true,
})
console.log('cloned from hyperbee')
// --- Compare ---
const original = await fs.promises.readFile(`${dir}/README.md`, 'utf8')
const cloned = await fs.promises.readFile(`${cloneDir}/README.md`, 'utf8')
console.log('original:', JSON.stringify(original))
console.log('cloned: ', JSON.stringify(cloned))
console.log('match:', original === cloned)
await core.close()