2

I am working on a git remote which translates the commits tree to native IPFS data structures on push and reconstructs them on fetch.

The process is working for commits, but when I try to recreate a tag the command succeeds, but the clone fails with the error: fatal: BUG: initial ref transaction called with existing refs.

To duplicate the issue, put this program on the PATH with the name git-remote-failtest. Then, run 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")
  }
})
dysbulic
  • 3,005
  • 2
  • 28
  • 48
  • I found https://www.spinics.net/lists/git/msg254318.html which explains git is trying to avoid me creating a reference that it wants to create, but git doesn't have the data to recreate a signed tag with a message. – dysbulic Jun 13 '20 at 13:45
  • A partial solution is to remove all the tags from the repository before passing control back to git. It avoids the error, but a cloned repository with `--tags` won't have any tags in it. – dysbulic Jun 19 '20 at 05:03

0 Answers0