libgit2 / libgit2/pygit2

'Failed to create commit: current tip is not the first parent' for basic commit

Aperta
#956 1 commento 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
Python
Stelle
1.7k
Fork
408
Merge medio
2g 57m
PR unite (30g)
7

Descrizione

I am trying to do something relatively simple which is just add and commit file changes to an existing repository as i would through the command line. The one complicating caveat is i am calling the code to do this from inside a submodule, however everything seems to be okay until the commit part.

In the folder above the code/submodule folder i have another which is the main git repo and which also has a folder of data i wish to monitor and commit changes of.

The code is

data_repo = pygit2.Repository('../')

index = data_repo.index
index.add_all(pathspecs=["tables/"]) # Because of the data repo path we are already in that repo local path so all paths relative to that
index.write()
tree = index.write_tree()
modified_tables = [ x for x in data_repo.status().keys() if 'tables' in x]

author = pygit2.Signature('Alice Author', 'alice@authors.tld')
committer = pygit2.Signature('GitRateWatcher', 'me@internet.com')
msg  = f"GitRateWatcher commit on {datetime.datetime.today().date()} modified tables: {', '.join(modified_tables)}"
oid = data_repo.create_commit('refs/heads/master', author, committer, msg, tree, [] )
data_repo.head.set_target(oid)

However when I try this i get

_pygit2.GitError: failed to create commit: current tip is not the first parent

if i remove the 'refs/heads/master' part it works but it basically does a rebase and wipes all previous stuff which is no good either. What am I missing?

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con la chiamata mostrata a data_repo.create_commit e con il target refs/heads/master, quindi esamina come il suo elenco di parent sia correlato al tip corrente del repository. Riproduci la struttura del sottomodulo e del repository padre descritta nell’issue e verifica che un nuovo commit preservi la cronologia esistente invece di effettuare un rebase. Il lavoro è completato quando il commit ha esito positivo mantenendo la cronologia precedente del branch.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
git, python
Ambito
devtools
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.