"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/lib/git.js" (11 Apr 2017, 3045 Bytes) of package /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 (function() {
    2   var _, addGitBashToEnv, addPortableGitToEnv, config, fs, npm, path, spawn;
    3 
    4   spawn = require('child_process').spawn;
    5 
    6   path = require('path');
    7 
    8   _ = require('underscore-plus');
    9 
   10   npm = require('npm');
   11 
   12   config = require('./apm');
   13 
   14   fs = require('./fs');
   15 
   16   addPortableGitToEnv = function(env) {
   17     var binPath, child, children, cmdPath, error, error1, githubPath, i, len, localAppData;
   18     localAppData = env.LOCALAPPDATA;
   19     if (!localAppData) {
   20       return;
   21     }
   22     githubPath = path.join(localAppData, 'GitHub');
   23     try {
   24       children = fs.readdirSync(githubPath);
   25     } catch (error1) {
   26       error = error1;
   27       return;
   28     }
   29     for (i = 0, len = children.length; i < len; i++) {
   30       child = children[i];
   31       if (!(child.indexOf('PortableGit_') === 0)) {
   32         continue;
   33       }
   34       cmdPath = path.join(githubPath, child, 'cmd');
   35       binPath = path.join(githubPath, child, 'bin');
   36       if (env.Path) {
   37         env.Path += "" + path.delimiter + cmdPath + path.delimiter + binPath;
   38       } else {
   39         env.Path = "" + cmdPath + path.delimiter + binPath;
   40       }
   41       break;
   42     }
   43   };
   44 
   45   addGitBashToEnv = function(env) {
   46     var binPath, cmdPath, gitPath;
   47     if (env.ProgramFiles) {
   48       gitPath = path.join(env.ProgramFiles, 'Git');
   49     }
   50     if (!fs.isDirectorySync(gitPath)) {
   51       if (env['ProgramFiles(x86)']) {
   52         gitPath = path.join(env['ProgramFiles(x86)'], 'Git');
   53       }
   54     }
   55     if (!fs.isDirectorySync(gitPath)) {
   56       return;
   57     }
   58     cmdPath = path.join(gitPath, 'cmd');
   59     binPath = path.join(gitPath, 'bin');
   60     if (env.Path) {
   61       return env.Path += "" + path.delimiter + cmdPath + path.delimiter + binPath;
   62     } else {
   63       return env.Path = "" + cmdPath + path.delimiter + binPath;
   64     }
   65   };
   66 
   67   exports.addGitToEnv = function(env) {
   68     if (process.platform !== 'win32') {
   69       return;
   70     }
   71     addPortableGitToEnv(env);
   72     return addGitBashToEnv(env);
   73   };
   74 
   75   exports.getGitVersion = function(callback) {
   76     var npmOptions;
   77     npmOptions = {
   78       userconfig: config.getUserConfigPath(),
   79       globalconfig: config.getGlobalConfigPath()
   80     };
   81     return npm.load(npmOptions, function() {
   82       var git, outputChunks, ref, spawned;
   83       git = (ref = npm.config.get('git')) != null ? ref : 'git';
   84       exports.addGitToEnv(process.env);
   85       spawned = spawn(git, ['--version']);
   86       outputChunks = [];
   87       spawned.stderr.on('data', function(chunk) {
   88         return outputChunks.push(chunk);
   89       });
   90       spawned.stdout.on('data', function(chunk) {
   91         return outputChunks.push(chunk);
   92       });
   93       spawned.on('error', function() {});
   94       return spawned.on('close', function(code) {
   95         var gitName, ref1, version, versionName;
   96         if (code === 0) {
   97           ref1 = Buffer.concat(outputChunks).toString().split(' '), gitName = ref1[0], versionName = ref1[1], version = ref1[2];
   98           version = version != null ? version.trim() : void 0;
   99         }
  100         return callback(version);
  101       });
  102     });
  103   };
  104 
  105 }).call(this);