Branch: Tag:

2010-10-04

2010-10-04 10:54:32 by Marcus Comstedt <marcus@mc.pp.se>

Re-run tests in post-commit hook

If amending a commit, the pre-commit hook will only see the
new changes being amended to the commit, not the changes
which were originally in the commit. Therefore, amending
an old broken commit might not show all problems unless
the result is also double checked.

431:    }   }    + class CommitHookUtilsRepo + { +  inherit CommitHookUtils; +  +  static string sha; +  +  string get_file(string filename, int|void allow_empty) +  { +  return get_committed_file(sha, filename, allow_empty); +  } +  +  string get_old_file(string filename, int|void allow_empty) +  { +  return get_committed_file(sha+"^", filename, allow_empty); +  } +  +  int entry_is_new(string filename) +  { +  return (!sizeof(run_git("ls-tree", sha+"^", "--", filename))) && +  sizeof(run_git("ls-tree", sha, "--", filename)); +  } +  +  int check_commit(string sha) +  { +  if (!has_prefix(sha, "HEAD")) +  write("Checking commit %s\n", sha); +  this_program::sha = sha; +  files_to_commit = +  split_z(run_git("diff", "--name-only", "-z", sha, sha+"^")); +  attrs = GitAttributes(get_file(".gitattributes", 1)); +  string ts_test = check_commit_timestamps(sha); +  if (ts_test) { +  write("Invalid timestamps: %s\n", ts_test); +  return 1; +  } +  string cm_test = check_commit_msg(sha); +  if (cm_test) { +  write("Commit message encoding problem:\n%s", cm_test); +  return 1; +  } +  return check_blocker_attributes() || +  check_gitattributes_files(); +  } + } +    /* Checks run before editing a commit message */      class PreCommitHook
476:      class PreReceiveHook   { -  inherit CommitHookUtils; +  inherit CommitHookUtilsRepo;    -  static string sha; -  -  string get_file(string filename, int|void allow_empty) -  { -  return get_committed_file(sha, filename, allow_empty); -  } -  -  string get_old_file(string filename, int|void allow_empty) -  { -  return get_committed_file(sha+"^", filename, allow_empty); -  } -  -  int entry_is_new(string filename) -  { -  return (!sizeof(run_git("ls-tree", sha+"^", "--", filename))) && -  sizeof(run_git("ls-tree", sha, "--", filename)); -  } -  -  int check_commit(string sha) -  { -  write("Checking commit %s\n", sha); -  this_program::sha = sha; -  files_to_commit = -  split_z(run_git("diff", "--name-only", "-z", sha, sha+"^")); -  attrs = GitAttributes(get_file(".gitattributes", 1)); -  string ts_test = check_commit_timestamps(sha); -  if (ts_test) { -  write("Invalid timestamps: %s\n", ts_test); -  return 1; -  } -  string cm_test = check_commit_msg(sha); -  if (cm_test) { -  write("Commit message encoding problem:\n%s", cm_test); -  return 1; -  } -  return check_blocker_attributes() || -  check_gitattributes_files(); -  } -  +     int check_tag_push(string old_sha, string new_sha, string ref_name)    {    string oldtag =
580:      class PostCommitHook   { +  inherit CommitHookUtilsRepo; +     void cleanup(string filename, mapping(string:string|int) attr)    {    if(attr->ident && attr->ident != GitAttributes.ATTR_FALSE &&
595:       int hook()    { -  array(string) committed_files = -  split_z(run_git("diff", "--name-only", "-z", "HEAD", "HEAD^")); -  GitAttributes attrs = -  GitAttributes(get_committed_file("HEAD", ".gitattributes", 1)); -  foreach(committed_files, string filename) +  if (check_commit("HEAD")) +  write("NOTICE: Your commit has errors, see above messages. Please amend before push.\n"); +  foreach(files_to_commit, string filename)    cleanup(filename, attrs->checkattr(filename));    string ts_test = check_commit_timestamps("HEAD");    if (ts_test) {