I'm using the Node version (the npm package via package.json )
I noted that it is possibile to create empty commits (commit with no one file modified)
It's tha same behaviour of the git commit --allow-empty command.
Is the allow-empty marked as the default for the commit somewhere in the code (I made a search but I was not able to find it)?
Is there a way to instruct the commit function to not use the allow-empty flag (an option or something like this)?
Hmm, no there isn't any check to prevent empty commits at the moment. I haven't run into a situation where that's a problem.... (Actually I use empty commits regularly to say, trigger webhooks / force CI to re-run on errors.) What is your workaround right now?
If someone is interested in adding such a check, probably the place to do it would be here right after we've constructed tree and resolved parent.
We could add it as a disallowEmpty option so we don't break the current behavior. Then for the 1.0 release we could switch the default to match the expected behavior and rename the option back to allowEmpty.
My current workarount is at application level.
I'm using statusMatrix and filtering the 1,1,1 results. It the resulting array is not empty I'll run the commit.
I have the same problem.
// isomorphic-git creates empty commits by default
const changes = (await git.statusMatrix({
fs,
dir
})).filter(([_, HEAD, WORKDIR, STAGE]) =>
// filter unchanged
// https://github.com/isomorphic-git/isomorphic-git/issues/865#issuecomment-533028127
// https://isomorphic-git.org/docs/en/statusMatrix.html
!((HEAD == 1) && (WORKDIR == 1) &&(STAGE == 1))
)
// do not commit empty
if (changes.length === 0) {
return
}
Most helpful comment
My current workarount is at application level.
I'm using statusMatrix and filtering the
1,1,1results. It the resulting array is not empty I'll run the commit.