libgit2 / libgit2/pygit2

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

Abierto
#956 1 comentario 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Lenguaje dominante
Python
Estrellas
1.7k
Forks
408
Merge medio
2 d 57 min
PR fusionados (30 d)
7

Descripción

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?

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con la llamada mostrada a data_repo.create_commit y el destino refs/heads/master; después, inspecciona cómo se relaciona su lista de padres con el tip actual del repositorio. Reproduce la disposición del submódulo y del repositorio padre descrita en el issue y verifica que un nuevo commit conserve el historial existente en lugar de hacerle rebase. Se considera terminado cuando el commit se realiza correctamente y conserva el historial previo de la rama.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
git, python
Área
devtools
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.