index.js 843 B

1234567891011121314151617181920212223242526272829303132333435
  1. /*!
  2. * git-config-path <https://github.com/jonschlinkert/git-config-path>
  3. *
  4. * Copyright (c) 2015-present, Jon Schlinkert.
  5. * Licensed under the MIT License.
  6. */
  7. 'use strict';
  8. const fs = require('fs');
  9. const os = require('os');
  10. const path = require('path');
  11. module.exports = function(type, options) {
  12. if (typeof type !== 'string') {
  13. options = type;
  14. type = null;
  15. }
  16. let opts = Object.assign({ cwd: process.cwd(), type }, options);
  17. let configPath;
  18. if (opts.type === 'global') {
  19. configPath = path.join(os.homedir(), '.gitconfig');
  20. } else {
  21. configPath = path.resolve(opts.cwd, '.git/config');
  22. }
  23. if (!fs.existsSync(configPath)) {
  24. if (typeof opts.type === 'string') return null;
  25. configPath = path.join(os.homedir(), '.config/git/config');
  26. }
  27. return fs.existsSync(configPath) ? configPath : null;
  28. };