Sto tentando di creare un commit a livello di codice in un repository esistente utilizzando Rugged (il binding Ruby di libgit2). Ho provato a seguire la documentazione fornita in Rugged README, ma penso che non corrisponda esattamente allo stato attuale del codebase. Continuo a ricevere errori quando provo in esecuzione il seguente codice:Come creare un commit a livello di codice con Rugged?
require 'rugged'
# Create an instance of the existing repository
repo = Rugged::Repository.new('/full/path/to/repo')
# grab the current Time object for now
curr_time = Time.now
# write a new blob to the repository, hang on to the object id
oid = repo.write("Some content for the this blob - #{curr_time}.", 'blob')
# get the index for this repository
index = repo.index
# add the blob to the index
index.add(:path => 'newfile.txt', :oid => oid, :mode => 0100644)
curr_tree = index.write_tree(repo)
curr_ref = 'HEAD'
author = {:email=>'[email protected]',:time=>curr_time,:name=>'username'}
new_commit = Rugged::Commit.create(repo,
:author => author,
:message => "Some Commit Message at #{curr_time}.",
:committer => author,
:parents => [repo.head.target],
:tree => curr_tree,
:update_ref => curr_ref)
L'errore corrente che sto ottenendo dice che c'è qualcosa che non va con la linea index.add
. Dice TypeError: wrong argument type nil (expected Fixnum)
.
Qualsiasi aiuto su una migliore comprensione di come creare un nuovo commit con rugged sarebbe molto apprezzato.
Aggiornamento
Ho appena aggiornato Rugged 0.16.0
-Rugged 0.18.0.gh.de28323
eseguendo gem install --prerelease rugged
. Il codice che ho descritto sopra sembra funzionare ora. Non sono sicuro del motivo per cui non ha funzionato con 0.16.0. Questa persona sembrava avere lo stesso problema descritto in this answer.
qual è il numero di riga? – fotanus
Si sta interrompendo sulla riga con 'index.add'. – jbranchaud
Spiacente, per qualche ragione ho letto il file index.add – fotanus