githelper.git / githelper.pike

version» Context lines:

githelper.git/githelper.pike:358:    "or remove the ident manually.\n",    @({filename})*2);;    }    return 1;    }    return 0;    }       int check_blocker_attributes()    { +  int err = 0;    foreach(files_to_commit, string filename) {    mapping(string:string|int) a = attrs->checkattr(filename);    if(a->foreign_ident == GitAttributes.ATTR_TRUE) {    if (!entry_is_new(filename)) {    write("File %s has the foreign_ident attribute. Please remove it before commit.\n", filename); -  return 1; +  err = 1; +  continue;    }    }    if(stringp(a->block_commit) || a->block_commit == GitAttributes.ATTR_TRUE) {    if (!entry_is_new(filename)) {    write("File %s is blocked from committing: %s\n", filename,    replace((stringp(a->block_commit)? a->block_commit :    "no explanation given"), "-", " ")); -  return 1; +  err = 1; +  continue;    }    }    if(a->ident && a->ident != GitAttributes.ATTR_FALSE &&    a->ident != GitAttributes.ATTR_UNSET) { -  if (check_ident(filename)) -  return 1; +  if (check_ident(filename)) { +  err = 1; +  continue;    }    } -  return 0; +     } -  +  return err; +  }       int check_gitattributes_files()    { -  +  int err = 0;    foreach(files_to_commit, string filename)    if(has_suffix(filename, "/.gitattributes")) {    write(".gitattributes are not allowed in subdirectories; "    "please remove %s\n", filename); -  return 1; +  err = 1;    }       if(search(files_to_commit, ".gitattributes")>=0) {    GitAttributes old_attrs =    GitAttributes(get_old_file(".gitattributes", 1));       array(string) new_f_i = sort(attrs->findattr("foreign_ident"));    array(string) old_f_i = sort(old_attrs->findattr("foreign_ident"));    array(string) added_fi = new_f_i - old_f_i;    array(string) removed_fi = old_f_i - new_f_i;       foreach(added_fi, string path) {    if(!has_prefix(path, "/") || search(path, "*")>=0) {    write("Commit adds unsupported foreign_ident: %s\n", path); -  return 1; +  err = 1; +  continue;    }    path = path[1..];    if (!entry_is_new(path)) {    write("Commit adds foreign_ident to existing file %s\n", path); -  return 1; +  err = 1;    }    }       foreach(removed_fi, string path) {    if(has_prefix(path, "/"))    path = path[1..];    if (search(files_to_commit, path)<0 &&    find_expanded_ident(get_file(path, 1))) {    write("Commit removes foreign_ident from unchanged file %s\n", path); -  return 1; +  err = 1;    }    }    } -  return 0; +  return err;    }   }      class CommitHookUtilsRepo   {    inherit CommitHookUtils;       static string sha;       string get_file(string filename, int|void allow_empty)
githelper.git/githelper.pike:458:       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); +  int err = 0;    if (ts_test) {    write("Invalid timestamps: %s\n", ts_test); -  return 1; +  err = 1;    }    string cm_test = check_commit_msg(sha);    if (cm_test) {    write("Commit message encoding problem:\n%s", cm_test); -  return 1; +  err = 1;    } -  return check_blocker_attributes() || -  check_gitattributes_files(); +  return check_blocker_attributes() | +  check_gitattributes_files() | +  err;    }   }      /* Checks run before editing a commit message */      class PreCommitHook   {    inherit CommitHookUtils;       string get_file(string filename, int|void allow_empty)
githelper.git/githelper.pike:507:    return 1;    }    }       int hook()    {    files_to_commit =    split_z(run_git("diff", "--staged", "--name-only", "-z"));    attrs = GitAttributes(get_file(".gitattributes", 1));    return -  check_attributes_staged() || -  check_blocker_attributes() || +  check_attributes_staged() | +  check_blocker_attributes() |    check_gitattributes_files();    }   }      /* Checks run before accepting a push */      class PreReceiveHook   {    inherit CommitHookUtilsRepo;