Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

295
Vistas
nodegit - How to know if a commit is empty (to avoid pushing empty commits)

I'm using nodegit and I can't figure out how to detect whether the there has been changes to commit.

Currently, I'm committing when an external event happens, but I don't know if this will cause a real difference in the files. I don't check whether the commit is empty before pushing, which led me to end up with lots of empty commits, I'd like to avoid that.

When doing it manually, I usually run a git status to check whether there were changes to commit, I was thinking about doing something similar here, but can't figure out how. (here is the documentation)

  console.log('committing...');
  const commitResult = await commitFile(`schema.json`, schemaAsString, `${appName} (${appId})`);
  const statuses = await repo.getStatus();
  console.log('getStatus status', statuses);
  console.log('getStatus status', statuses[0].status());
  console.log('getStatus isModified', statuses[0].isModified());
  console.log('getStatus path', statuses[0].path());
  console.log('getStatus statusBit', statuses[0].statusBit());

  console.log('pushing...');
  const pushResult = await push(repo);
  console.log('pushResult', pushResult);
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

In general : from the command line, another way to see if there are differences at all is to run git diff HEAD. The diff is empty iff there are no differences.

You seem to care only about schema.json in your script : from the command line that would be git diff HEAD -- schema.json.

If you manage to generate a similar command in nodegit (get the diff for schema.json between HEAD and the worktree ), you can use it as a condition at the very beginning of your script.

about 4 years ago · Juan Pablo Isaza Denunciar

0

I figured it out by trying things a bit at random.

I use the Index checksum, and compare it before and after committing.

If the commit is empty, the checksum doesn't change. If the commit isn't empty, the checksum changes.

Based on that, it's easy to write a simple condition to perform the push or not.

  const repo = await clone(repositoryLocalPath);
  console.log('repo', repo);
  const indexBeforeCommit: Index = await repo.refreshIndex();
  const indexBeforeCommitChecksum = indexBeforeCommit.checksum().tostrS();
  console.log('indexBeforeCommit checksum', indexBeforeCommitChecksum);

  console.log('committing...');
  const commitId = await commitFile(`schema.json`, schemaAsString, `Airtable - ${appName} (${appId})`);
  const indexAfterCommit: Index = await repo.refreshIndex();
  const indexAfterCommitChecksum = indexAfterCommit.checksum().tostrS();
  console.log('indexAfterCommit checksum', indexAfterCommitChecksum);

  if (indexBeforeCommitChecksum !== indexAfterCommitChecksum) {
    console.log('pushing...');
    const pushResult = await push(repo);
    console.log('pushResult', pushResult);
  } else {
    console.log('no changes to push');
  }
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda