code: function lastHunkStagedPromise(result) {
      return NodeGit.Diff.indexToWorkdir(repo, index, {
        flags:
          NodeGit.Diff.OPTION.SHOW_UNTRACKED_CONTENT |
          NodeGit.Diff.OPTION.RECURSE_UNTRACKED_DIRS |
          (additionalDiffOptions || 0)
      })
      .then(function(diff) {
        return diff.patches();
      })
      .then(function(patches) {
        var pathPatch = patches.filter(function(patch) {
          return patch.newFile().path() === filePath;
        });
        var emptyPatch = false;
        if (pathPatch.length > 0) {
          // No hunks, unchanged file mode, and no type changes.
          emptyPatch = pathPatch[0].size() === 0 &&
            pathPatch[0].oldFile().mode() === pathPatch[0].newFile().mode() &&
            !pathPatch[0].isTypeChange();
        }
        if (emptyPatch) {
          return index.addByPath(filePath)
            .then(function() {
              return index.write();
            });
        }
  
        return result;
      });
    }
docs: The following chain checks if there is a patch with no hunks left for the file, and no filemode changes were done on the file. It is then safe to stage the entire file so the file doesn't show as having unstaged changes in `git status`. Also, check if there are no type changes.