<commit_before>var fs = require("fs");
var g = require("../src/gitlet");
var nodePath = require("path");
var testUtil = require("./test-util");

describe("update-index", function() {
  beforeEach(testUtil.initTestDataDir);

  it("should throw if not in repo", function() {
    expect(function() { g.update_index(); })
      .toThrow("fatal: Not a gitlet repository (or any of the parent directories): .gitlet");
  });

  describe("pathspec stipulations", function() {
    it("should throw if path does not match existing working copy file", function() {
      g.init();
      expect(function() { g.update_index("blah"); })
        .toThrow("error: blah: does not exist\n");
    });

    it("should throw rel path if not in root and pathspec does not match file", function() {
      g.init();
      testUtil.createFilesFromTree({ "1": { "2": {}}})
      process.chdir("1/2");
      expect(function() { g.update_index("blah"); })
        .toThrow("error: 1/2/blah: does not exist\n");
    });

    it("should throw rel path if not in root and path is dir", function() {
      g.init();
      testUtil.createFilesFromTree({ "1": { "2": {}}})
      process.chdir("1");
      expect(function() { g.update_index("2"); })
        .toThrow("error: 1/2: is a directory - add files inside instead\n");
    });
  });

  describe("adding files to index", function() {
    it("should add a file to an empty index and create object", function() {
      g.init();
      fs.writeFileSync("README.md", "this is a readme");
      g.update_index("README.md", { add: true });

      var readmeHash = g.hash_object("README.md");<commit_msg>Update tests to check for latest error message copy<commit_after>var fs = require("fs");
var g = require("../src/gitlet");
var nodePath = require("path");
var testUtil = require("./test-util");

describe("update-index", function() {
  beforeEach(testUtil.initTestDataDir);

  it("should throw if not in repo", function() {
    expect(function() { g.update_index(); })
      .toThrow("fatal: Not a gitlet repository (or any of the parent directories): .gitlet");
  });

  describe("pathspec stipulations", function() {
    it("should throw if path does not match existing working copy file", function() {
      g.init();
      expect(function() { g.update_index("blah"); })
        .toThrow("error: blah: does not exist and --remove not passed\n");
    });

    it("should throw rel path if not in root and pathspec does not match file", function() {
      g.init();
      testUtil.createFilesFromTree({ "1": { "2": {}}})
      process.chdir("1/2");
      expect(function() { g.update_index("blah"); })
        .toThrow("error: 1/2/blah: does not exist and --remove not passed\n");
    });

    it("should throw rel path if not in root and path is dir", function() {
      g.init();
      testUtil.createFilesFromTree({ "1": { "2": {}}})
      process.chdir("1");
      expect(function() { g.update_index("2"); })
        .toThrow("error: 1/2: is a directory - add files inside instead\n");
    });
  });

  describe("adding files to index", function() {
    it("should add a file to an empty index and create object", function() {
      g.init();
      fs.writeFileSync("README.md", "this is a readme");
      g.update_index("README.md", { add: true });

      var readmeHash = g.hash_object("README.md");
{'fraction_non_alphanumeric': 0.17328519855595667, 'fraction_numerical': 0.007220216606498195, 'mean_word_length': 3.2464878671775224, 'pattern_counts': {'":': 8, '<': 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': '7525788', 'n_tokens_mistral': 1035, 'n_tokens_neox': 1004, 'n_words': 303}