<commit_before>/*
 * git.js: Implementation of the repository pattern for remote git repositories.
 *
 * (C) 2010, Nodejitsu Inc.
 *
 */

var util = require('util'),
    path = require('path'),
    exec = require('child_process').exec,
    haibu = require('../../haibu'),
    Repository = require('./repository').Repository;

//
// ### function Git (app, options)
// #### @app {App} Application manifest to wrap
// #### @options {Object} Options for this instance
// Constructor function for the Git repository object. Responsible
// for cloning, and updating Git repositories.
//
var Git = exports.Git = function (app, options) {
  return Repository.call(this, app, options);
};

// Inherit from Repository
util.inherits(Git, Repository);

//
// ### function validate ()
// #### @keys {Array||String} The keys to check in app. (i.e. 'scripts.start')
// #### @app {Object} (optional) The app object to check. if not given this.app will be used.
// #### @return {Error|| undefined} undefined if valid, Error if not
// Checks Application configuration attributes used by this repository type
//
Git.prototype.validate = function (keys, app) {
  keys = keys || [];
  return Repository.prototype.validate.call(this, keys.concat('repository.url'), app);
}

//
// ### function init (callback)
// #### @callback {function} Continuation to respond to.
// Initializes the git repository associated with the application
// and this instance. Checks out the specific branch in `app.repository.branch`
// if it exists. Initializes and updates git submodules. Initializes npm dependencies
// through calling `self.installDependencies`. Build brunch through calling 'self.buildBrunch'.
//
Git.prototype.init = function (callback) {
  var self = this;

  function installNpm () {
    self.installDependencies(function (err, packages) {
      return err ? callback(err) : callback(null, true, packages);
    });
  }

  haibu.emit('git:clone', 'info', {
    type: 'git',
    user: self.app.user,
    name: self.app.name,
    from: self.app.repository.url,
    to: self.appDir
  });


  // TODO (indexzero): Validate the security of this regular expression since it is on the command line.
  var commands, match = self.app.repository.url.match(/\/([\w\-_\.]+)\.git$/);
  if (!match) {
    var err = new Error('Invalid git url: ' + self.app.repository.url);
    err.blame = {
      type: 'user',
      message: 'Repository configuration present but provides invalid Git URL'
    };
    return callback(err);
  }

  // Set the home directory of the app managed by this instance.
  self._setHome(match[1]);

  // Setup the git commands to be executed
  commands = [
    'cd ' + self.appDir + ' && git clone ' + self.app.repository.url,
    'cd ' + path.join(self.appDir, match[1])
  ];

  if (self.app.repository.branch) {
    commands[1] += ' && git checkout ' + self.app.repository.branch;
  }
<commit_msg>code cleaning<commit_after>/*
 * git.js: Implementation of the repository pattern for remote git repositories.
 *
 * (C) 2010, Nodejitsu Inc.
 *
 */

var util = require('util'),
    path = require('path'),
    exec = require('child_process').exec,
    haibu = require('../../haibu'),
    Repository = require('./repository').Repository;

//
// ### function Git (app, options)
// #### @app {App} Application manifest to wrap
// #### @options {Object} Options for this instance
// Constructor function for the Git repository object. Responsible
// for cloning, and updating Git repositories.
//
var Git = exports.Git = function (app, options) {
  return Repository.call(this, app, options);
};

// Inherit from Repository
util.inherits(Git, Repository);

//
// ### function validate ()
// #### @keys {Array||String} The keys to check in app. (i.e. 'scripts.start')
// #### @app {Object} (optional) The app object to check. if not given this.app will be used.
// #### @return {Error|| undefined} undefined if valid, Error if not
// Checks Application configuration attributes used by this repository type
//
Git.prototype.validate = function (keys, app) {
  keys = keys || [];
  return Repository.prototype.validate.call(this, keys.concat('repository.url'), app);
}

//
// ### function init (callback)
// #### @callback {function} Continuation to respond to.
// Initializes the git repository associated with the application
// and this instance. Checks out the specific branch in `app.repository.branch`
// if it exists. Initializes and updates git submodules. Initializes npm dependencies
// through calling `self.installDependencies`.
//
Git.prototype.init = function (callback) {
  var self = this;

  function installNpm () {
    self.installDependencies(function (err, packages) {
      return err ? callback(err) : callback(null, true, packages);
    });
  }

  haibu.emit('git:clone', 'info', {
    type: 'git',
    user: self.app.user,
    name: self.app.name,
    from: self.app.repository.url,
    to: self.appDir
  });

  // TODO (indexzero): Validate the security of this regular expression since it is on the command line.
  var commands, match = self.app.repository.url.match(/\/([\w\-_\.]+)\.git$/);
  if (!match) {
    var err = new Error('Invalid git url: ' + self.app.repository.url);
    err.blame = {
      type: 'user',
      message: 'Repository configuration present but provides invalid Git URL'
    };
    return callback(err);
  }

  // Set the home directory of the app managed by this instance.
  self._setHome(match[1]);

  // Setup the git commands to be executed
  commands = [
    'cd ' + self.appDir + ' && git clone ' + self.app.repository.url,
    'cd ' + path.join(self.appDir, match[1])
  ];

  if (self.app.repository.branch) {
    commands[1] += ' && git checkout ' + self.app.repository.branch;
  }

{'fraction_non_alphanumeric': 0.149895178197065, 'fraction_numerical': 0.002445842068483578, 'mean_word_length': 3.3503039513677813, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '217664', 'n_tokens_mistral': 1705, 'n_tokens_neox': 1665, 'n_words': 552}