2

我正在开发一个git遥控器,它在推送时将提交树转换为本地 IPFS 数据结构,并在获取时重建它们。

该过程适用于提交,但是当我尝试重新创建标签时,命令成功,但克隆失败并出现错误:fatal: BUG: initial ref transaction called with existing refs.

要复制问题,请将此程序放在PATH名称为git-remote-failtest. 然后,运行git clone failtest:: test

#!/usr/bin/env node

const fs = require('fs')
const Git = require('nodegit')
const readline = require('readline')

const fetch = async () => {
  const repo = await Git.Repository.open(process.env.GIT_DIR)
  const tb = await Git.Treebuilder.create(repo, null)
  const buffer = Buffer.from('This is a test…')
  const blobOID = await Git.Blob.createFromBuffer(repo, buffer, buffer.length)
  const mode = 33188
  tb.insert('test.txt', blobOID, mode)
  const treeOID = await tb.write()
  const tree = await Git.Tree.lookup(repo, treeOID)
  const author = Git.Signature.create('Tester', 'test@test.com', 987654321, -240)
  const updateRef = null
  const encoding = null
  const message = 'This is a commit message…'
  const parents = []
  const commitOID = await Git.Commit.create(
    repo, updateRef, author, author, encoding, message, tree, parents.length, parents
  )
  const force = true ? 1 : 0
  repo.createBranch('master', commitOID, force)
  const name = 'v/0.0.1'
  const signature = "----START PGP----\nsigsigsig\n----END PGP----"
  const sign = (tag) => ({
    code: Git.Error.CODE.OK,
    signedData: signature,
  })
  const tag = await Git.Tag.createWithSignature(
    repo, name, commitOID, author, message, force, sign
  )
}

const rl = readline.createInterface({
  input: process.stdin, output: process.stdout, terminal: false,
})

rl.on('line', async (line) => {
  process.stderr.write(`${line}\n`)
  if(line === 'capabilities') {
    process.stdout.write("fetch\n\n")
  } else if(line.startsWith('list')) {
    process.stdout.write("@refs/heads/master HEAD\n")
    process.stdout.write("c7b06b3995e89c40294d540d4a6296ba86c7ce43 refs/heads/master\n")
    process.stdout.write("05ef40aab914c90ecaa4250c03fce523d8683c5d refs/tags/v/0.0.1\n\n")
  } else if(line.startsWith('fetch')) {
  } else if(line === '') {
    await fetch()
    process.stdout.write("\n\n")
  }
})
4

0 回答 0