// Generated by CoffeeScript 1.9.3
(function() {
  var Git, Repo, exec;

  exec = require('child_process').exec;

  Repo = require('./repo');

  module.exports = Git = function(path, bare, git_options) {
    if (bare == null) {
      bare = false;
    }
    if (git_options == null) {
      git_options = {
        maxBuffer: Git.maxBuffer
      };
    }
    return new Repo(path, bare, git_options);
  };

  Git.maxBuffer = 5000 * 1024;

  Git.init = function(path, bare, callback) {
    var bash, ref;
    if (!callback) {
      ref = [callback, bare], bare = ref[0], callback = ref[1];
    }
    if (bare) {
      bash = "git init --bare .";
    } else {
      bash = "git init .";
    }
    return exec(bash, {
      cwd: path
    }, function(err, stdout, stderr) {
      if (err) {
        return callback(err);
      }
      return callback(err, new Repo(path, bare, {
        maxBuffer: Git.maxBuffer
      }));
    });
  };

  Git.clone = function(repository, path, depth, callback) {
    var bash;
    if (depth == null) {
      depth = 0;
    }
    if (typeof depth === 'function') {
      callback = depth;
      depth = 0;
    }
    if (depth === 0 || typeof depth !== 'number') {
      bash = "git clone \"" + repository + "\" \"" + path + "\"";
    } else {
      bash = "git clone \"" + repository + "\" \"" + path + "\" --depth \"" + depth + "\"";
    }
    return exec(bash, function(err, stdout, stderr) {
      if (err) {
        return callback(err);
      }
      return callback(err, new Repo(path, false, {
        maxBuffer: Git.maxBuffer
      }));
    });
  };

}).call(this);
