You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
How to check count of changed files to avoid empty commits #1976
Index.entryCount() does not return the number of staged files, rather the total number of files checked in at the current index. To get the number of staged changes you can use:
constrepo=awaitRepository.open(repoPath);constindex=awaitrepo.refreshIndex();constflags: Diff.OPTION=Diff.OPTION.IGNORE_WHITESPACE;// not needed, can be 0consthead=awaitrepo.getHeadCommit();// In an "empty" repository the `oldTree` parameter (here `await head.getTree()`) must be `undefined`.conststagedDiff=awaitDiff.treeToIndex(repo,awaithead.getTree(),index,{ flags });constnumberOfStagedChanges=stagedDiff.numDeltas();
And to get the files which are changed, but not yet staged, could be something like:
Activity
weedz commentedon Mar 21, 2023
Index.entryCount()does not return the number of staged files, rather the total number of files checked in at the current index. To get the number of staged changes you can use:And to get the files which are changed, but not yet staged, could be something like: