githelper.git / githelper.pike

version» Context lines:

githelper.git/githelper.pike:50:   {    return run_git_ex(0, @args);   }      /* Hooks */      /* Checks run before editing a commit message */      class PreCommitHook   { +  string get_staged_file(string filename) +  { +  string sha; +  if (2 != sscanf(run_git("ls-files", "--stage", "--", filename), +  "%*o %s ", sha)) +  fail("Unable to parse output from git ls-files...\n"); +  return run_git("cat-file", "blob", sha); +  } +     int check_attributes_staged()    {    // We don't allow .gitattributes to differ between wt and index,    // because that could mean the committed stuff ends up with different    // attributes than they have right now...       if (sizeof(run_git("diff", "--name-only", ".gitattributes"))) {    write("You have unstaged changes to .gitattributes.\n"    "Please add or stash them before commit.\n");    return 1;    }    }    -  +  int check_ident(string filename) +  { +  string data = get_staged_file(filename); +  int p=0; +  while ((p = search(data, "$Id", p))>=0) { +  if (data[p..p+3] != "$Id$") { +  write("File %s contains an expanded ident.\n" +  "Try 'git reset %s; git add %s', " +  "or remove the ident manually.\n", +  @({filename})*3); +  return 1; +  } +  p += 4; +  } +  return 0; +  } +     int check_blocker_attributes(array(string) files_to_commit)    { -  constant attrs_to_check = ({ "foreign_ident", "block_commit" }); +  constant attrs_to_check = ({ "foreign_ident", "block_commit", "ident" });    foreach(run_git("check-attr", @attrs_to_check,    "--", @files_to_commit) / "\n" - ({""}),    string line) {    array(string) parts = line / ": ";    if (sizeof(parts) != 3)    fail("Unexpected output from git check-attr, please fix check_blocker_attributes()\n");    [string filename, string attribute, string value] = parts;    if (value != "unspecified") {    switch (attribute) {    case "foreign_ident":    write("File %s has the foreign_ident attribute. Please remove it before commit.\n", filename);    return 1;    case "block_commit":    write("File %s is blocked from committing: %s\n", filename,    replace(value, "-", " "));    return 1; -  +  case "ident": +  if (value == "unset") +  break; +  if (check_ident(filename)) +  return 1; +  break;    }    }    }    return 0;    }       int hook()    {    array(string) files_to_commit =    split_z(run_git("diff", "--staged", "--name-only", "-z"));