githelper.git / githelper.pike

version» Context lines:

githelper.git/githelper.pike:424:    if (search(files_to_commit, path)<0) {    write("Removed foreign_ident from unchanged file %s\n", path);    return 1;    }    }    }    return 0;    }   }    + 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   {    inherit CommitHookUtils;       string get_file(string filename, int|void allow_empty)    {    return get_staged_file(filename, allow_empty);    }
githelper.git/githelper.pike:469:    check_attributes_staged() ||    check_blocker_attributes() ||    check_gitattributes_files();    }   }      /* Checks run before accepting a push */      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 =    String.trim_all_whites(run_git_ex(1, "rev-parse", "--verify",    "-q", ref_name));    if (sizeof(oldtag) && oldtag != new_sha) {    write("Tag %s already exists with value %s, will not move it\n",    ref_name, oldtag);    return 1;    }
githelper.git/githelper.pike:573:    return 1;    }    return 0;    }   }      /* Do housekeeping after a commit */      class PostCommitHook   { +  inherit CommitHookUtilsRepo; +     void cleanup(string filename, mapping(string:string|int) attr)    {    if(attr->ident && attr->ident != GitAttributes.ATTR_FALSE &&    attr->ident != GitAttributes.ATTR_UNSET &&    search(get_committed_file("HEAD", filename, 1), unexpanded_id)>=0)    if(sizeof(run_git("diff", "--name-only", "--", filename))) {    write("NOTICE: The file %s has a stale ident,\n but I won't touch it since you have unstaged changes.\n", filename);    } else {    // write("Checking out %s, to fix stale ident...\n", filename);    run_git("checkout", "HEAD", "--", filename);    }    }       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) {    write("NOTICE: Your commit has invalid timestamps: %s\n", ts_test);    write("Please amend it before pushing.\n");    }    string cm_test = check_commit_msg("HEAD");    if (cm_test) {    write("NOTICE: Your commit message has an encoding problem:\n%s", cm_test);    write("Please ament it before pushing.\n");