<commit_before>var path = require("path");
var assert = require("assert");
var fse = require("fs-extra");
var local = path.join.bind(path, __dirname);
var _ = require("lodash");

describe("Clone", function() {
  var NodeGit = require("../../");
  var Repository = NodeGit.Repository;
  var Clone = NodeGit.Clone;

  var clonePath = local("../repos/clone");

  var sshPublicKeyPath = local("../id_rsa.pub");
  var sshPrivateKeyPath = local("../id_rsa");
  var sshEncryptedPublicKeyPath = local("../encrypted_rsa.pub");
  var sshEncryptedPrivateKeyPath = local("../encrypted_rsa");

  // Set a reasonable timeout here now that our repository has grown.
  this.timeout(30000);

  beforeEach(function() {
    return fse.remove(clonePath).catch(function(err) {
      console.log(err);

      throw err;
    });
  });

  it.skip("can clone with http", function() {
    var test = this;
    var url = "http://git.tbranyen.com/smart/site-content";

    return Clone(url, clonePath).then(function(repo) {
      assert.ok(repo instanceof Repository);
      test.repository = repo;
    });
  });

  it("can clone with https", function() {
    var test = this;
    var url = "https://github.com/nodegit/test.git";
    var opts = {
        fetchOpts: {
          callbacks: {
            certificateCheck: () => 0
        }
      }
    };

    return Clone(url, clonePath, opts).then(function(repo) {
      assert.ok(repo instanceof Repository);
      test.repository = repo;
    });
  });

  it("can clone twice with https using same config object", function() {
    var test = this;
    var url = "https://github.com/nodegit/test.git";
    var progressCount = 0;
    var opts = {
      fetchOpts: {
        callbacks: {
          transferProgress: function(progress) {
            progressCount++;
          }
        }
      }
    };

    return Clone(url, clonePath, opts)
      .then(function(repo) {
        assert.ok(repo instanceof Repository);
        assert.notEqual(progressCount, 0);
        return fse.remove(clonePath);
      })<commit_msg>Test clone to long path<commit_after>var path = require("path");
var assert = require("assert");
var fse = require("fs-extra");
var local = path.join.bind(path, __dirname);
var _ = require("lodash");

const generatePathWithLength = (base, length) => {
  let path = `${base}/`;
  const baseLength = path.length;
  const remaining = length - baseLength;

  for (let i = 0; i < remaining; ++i) {
		// add a slash every 240 characters, but not as first or last character
    if (i % 239 == 0 && i != remaining - 1 && i != 0) {
      path += "/";
    } else {
      path += "a";
    }
  }

  assert.ok(path.length === length);

  return path;
};

describe("Clone", function() {
  var NodeGit = require("../../");
  var Repository = NodeGit.Repository;
  var Clone = NodeGit.Clone;

  var clonePath = local("../repos/clone");
  var longClonePath = generatePathWithLength(clonePath, 600);

  var sshPublicKeyPath = local("../id_rsa.pub");
  var sshPrivateKeyPath = local("../id_rsa");
  var sshEncryptedPublicKeyPath = local("../encrypted_rsa.pub");
  var sshEncryptedPrivateKeyPath = local("../encrypted_rsa");

  // Set a reasonable timeout here now that our repository has grown.
  this.timeout(30000);

  beforeEach(function() {
    if (process.platform === "win32") {
      NodeGit.Libgit2.opts(NodeGit.Libgit2.OPT.SET_WINDOWS_LONGPATHS, 0);
    }

    return fse.remove(clonePath)
      .then(function() {
        return fse.remove(longClonePath);
      })
      .catch(function(err) {
        console.log(err);
        throw err;
      });
  });

  it.skip("can clone with http", function() {
    var test = this;
    var url = "http://git.tbranyen.com/smart/site-content";

    return Clone(url, clonePath).then(function(repo) {
      assert.ok(repo instanceof Repository);
      test.repository = repo;
    });
  });

  it("can clone with https", function() {
    var test = this;
    var url = "https://github.com/nodegit/test.git";
    var opts = {
        fetchOpts: {
          callbacks: {
            certificateCheck: () => 0
        }
      }
    };

    return Clone(url, clonePath, opts).then(function(repo) {
      assert.ok(repo instanceof Repository);
      test.repository = repo;
    });
  });

  it("can clone into long path if opt set", function() {
    var test = this;
    var url = "https://github.com/nodegit/test.git";
    var opts = {
        fetchOpts: {
          callbacks: {
            certificateCheck: () => 0
        }
      }
    };

    fse.ensureDirSync(longClonePath);

    if (process.platform === "win32") {
      NodeGit.Libgit2.opts(NodeGit.Libgit2.OPT.SET_WINDOWS_LONGPATHS, 1);
    }

    return Clone(url, longClonePath, opts).then(function(repo) {
      assert.ok(repo instanceof Repository);
      test.repository = repo;
    });
  });

  it("can't clone into long path if opt not set on win32", function() {
    if (process.platform !== "win32") {
      this.skip();
    }

    var url = "https://github.com/nodegit/test.git";
    var opts = {
        fetchOpts: {
          callbacks: {
            certificateCheck: () => 0
        }
      }
    };

    fse.ensureDirSync(longClonePath);

    NodeGit.Libgit2.opts(NodeGit.Libgit2.OPT.SET_WINDOWS_LONGPATHS, 0);

    return Clone(url, longClonePath, opts).then(function(repo) {
      assert.fail("Clone should not succeed");
    }).catch(function(error) {
      assert.ok(error instanceof Error);
    });
  });

  it("can clone twice with https using same config object", function() {
    var test = this;
    var url = "https://github.com/nodegit/test.git";
    var progressCount = 0;
    var opts = {
      fetchOpts: {
        callbacks: {
          transferProgress: function(progress) {
            progressCount++;
          }
        }
      }
    };

    return Clone(url, clonePath, opts)
      .then(function(repo) {
        assert.ok(repo instanceof Repository);
        assert.notEqual(progressCount, 0);
        return fse.remove(clonePath);
      })
{'fraction_non_alphanumeric': 0.14761746084638455, 'fraction_numerical': 0.007997334221926024, 'mean_word_length': 2.5436835891381344, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 8, 'https://': 6, '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': '6570605', 'n_tokens_mistral': 1949, 'n_tokens_neox': 1879, 'n_words': 428}