githelper.git
/
githelper.pike
version
»
Context lines:
10
20
40
80
file
none
3
githelper.git/githelper.pike:344:
} return r; } protected string _sprintf(int type) { return type=='O' && sprintf("GitAttributes(%O)\n", attrs); } }
-
-
/* Hooks */
-
-
class CommitHookUtils
-
{
-
protected array(string) files_to_commit;
-
GitAttributes attrs;
-
+
private string git_dir;
-
+
private string git_commondir;
string get_git_dir() { return git_dir || (git_dir = String.trim_all_whites(run_git("rev-parse", "--git-dir"))); }
-
+
string get_git_commondir()
+
{
+
if (git_commondir) return git_commondir;
+
+
string dir = get_git_dir();
+
string commondir = Stdio.read_bytes(combine_path(dir, "commondir"));
+
if (!commondir) {
+
// Not a worktree.
+
return git_commondir = dir;
+
}
+
// We are in a worktree.
+
// NB: commondir may be relative to gitdir. It may also have
+
// a terminating linefeed.
+
return git_commondir = combine_path(dir, String.trim_all_whites(commondir));
+
}
+
+
+
/* Hooks */
+
+
class CommitHookUtils
+
{
+
protected array(string) files_to_commit;
+
GitAttributes attrs;
+
class GithelperPlugin { optional string check_message_body(string sha, array(string) headers, string body); optional int(0..1) check_commit(string branch, string sha, array(string) paths); } GithelperPlugin plugin; private class PluginHandler { mixed resolv(string symbol, string file) { switch(symbol) { case "GithelperPlugin": return GithelperPlugin; case "get_git_dir": return get_git_dir;
-
+
case "get_git_commondir": return get_git_commondir;
} return master()->resolv(symbol, file); } } private PluginHandler plugin_handler = PluginHandler(); protected void create() { if (!sizeof(plugin_name || "")) return;
-
string plugin_path = combine_path(get_git_
dir
(),
+
string plugin_path = combine_path(get_git_
commondir
(),
"hooks/githelper-plugins", plugin_name); if (Stdio.exist(plugin_path)) { program(GithelperPlugin) plugin_program = compile_file(plugin_path, plugin_handler); plugin = plugin_program(); } else { write("NOTICE: Plugin %s not found.\n", plugin_path); write("You may want to reinstall githelper.\n"); }
githelper.git/githelper.pike:683:
protected mapping(string:AccessLevel) groups = ([ "scratch": ACCESS_FULL, ]); protected array(string) commits_to_check = ({}); protected mapping(string:array(string)) branch_commits = ([]); protected void parse_groups(string user) {
-
string git_
dir
= get_git_
dir
();
+
string git_
commondir
= get_git_
commondir
();
groups[user] = ACCESS_FULL; groups["tracking"] = ACCESS_EXISTING;
-
string group_data = Stdio.read_bytes(combine_path(git_
dir
, "info/group"));
+
string group_data =
+
Stdio.read_bytes(combine_path(git_
commondir
, "info/group"));
if (!group_data) return; foreach(replace(group_data, "\r", "\n")/"\n", string line) { array(string) fields = map(line/":", String.trim_all_whites); // NB: We currently only care about fields 0 (group name) // and 3 (member list). The first member of a group is // considered the primary member, and has full access.
githelper.git/githelper.pike:982:
return 0; } } /* Main helper */ class GitHelper { void setup_hooks() {
-
constant hooksdir = "hooks";
+
if (!sizeof(hooks)) return;
-
+
string hooksdir = combine_path(get_git_commondir(), "hooks");
if (!file_stat(hooksdir)) { write("Creating the hooks directory\n"); if (!mkdir(hooksdir)) iofail("Failed to create %s", hooksdir); } foreach (hooks; string name; program p) { string path = combine_path(hooksdir, name); string src = p?__FILE__:combine_path(__DIR__, name); if (!file_stat(src)) { iofail("Source file %s not found");