fix HEAD ref

master
cyhhao 2 years ago
parent b47a4a254c
commit 1c59e0cf28

@ -155,7 +155,13 @@ class Git {
return "non-fast forward" return "non-fast forward"
} }
} }
let status = await this.storage.setRef(dst, newSha) let status
if (dst == "HEAD") {
status = await this.storage.setRef(`HEAD:${newSha}`, "0000000000000000000000000000000000000000")
} else {
status = await this.storage.setRef(dst, newSha)
}
if (status == Status.SUCCEED) { if (status == Status.SUCCEED) {
return null return null
} }
@ -181,6 +187,12 @@ class Git {
async get_refs(forPush: boolean): Promise<Ref[]> { async get_refs(forPush: boolean): Promise<Ref[]> {
let refs = await this.storage.listRefs() let refs = await this.storage.listRefs()
for (let item of refs) {
if (item.sha == "0000000000000000000000000000000000000000") {
item.sha = item.ref.split("HEAD:")[1]
item.ref = "HEAD"
}
}
return refs return refs
} }

@ -4,7 +4,7 @@ import parse from 'parse-git-config'
import abi from './abi.js' import abi from './abi.js'
// path -> /ab/123ab3123 // path -> /ab/123ab3123
export async function callContractMethod ({ export async function callContractMethod({
method = 'upload', method = 'upload',
path, path,
file, file,
@ -23,7 +23,7 @@ export async function callContractMethod ({
: ethers.Wallet.fromMnemonic(key) : ethers.Wallet.fromMnemonic(key)
etherWallet = etherWallet.connect(provider) etherWallet = etherWallet.connect(provider)
const contract = new ethers.Contract('0x680336910D9357F6aDf26c0d61eAB8e65998Ab2d', abi, etherWallet); const contract = new ethers.Contract('0xb940B75947F64C9fe0b4B2b6c56Fc9DEF03bBb5F', abi, etherWallet);
const pathBuffer = path ? Buffer.from(path) : '' const pathBuffer = path ? Buffer.from(path) : ''
if (method === 'upload') { if (method === 'upload') {
@ -52,23 +52,7 @@ export async function callContractMethod ({
sha: i[0].slice(2) sha: i[0].slice(2)
})) }))
refs = refs.concat([{ ref: 'HEAD', sha: 'refs/heads/main' }]) // refs = refs.concat([{ ref: 'HEAD', sha: 'refs/heads/main' }])
return refs return refs
} }
} }
// callContractMethod('kai', 'upload', '/07/549ed56229550960d2cb32b086df52304d9a86')
// callContractMethod('kai', 'download', '/07/549ed56229550960d2cb32b086df52304d9a86')
// callContractMethod({
// wallet: 'kai',
// method: 'setRef',
// path: '/refs/heads/master',
// sha: '07549ed56229550960d2cb32b086df52304d9a86'
// })
callContractMethod({
wallet: 'kai',
method: 'listRefs',
// path: '/refs/heads/master',
// sha: '07549ed56229550960d2cb32b086df52304d9a86'
})
Loading…
Cancel
Save