index.js 874 B

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