githelper.git
/
githelper.pike
version
»
Context lines:
10
20
40
80
file
none
3
githelper.git/githelper.pike:550:
// 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_not_tracking()
+
{
+
string local_branch = run_git("symbolic-ref", "HEAD");
+
if (!has_prefix(local_branch, "refs/heads/")) {
+
write("Attempt to commit to non-branch: %s.\n", local_branch);
+
}
+
if (has_prefix(local_branch, "refs/heads/tracking/")) {
+
write("Attempt to commit to tracking branch.\n");
+
return 1;
+
}
+
local_branch = local_branch[sizeof("refs/heads/")..];
+
if (has_suffix(local_branch, "\n")) {
+
local_branch = local_branch[..<1];
+
}
+
string remote_branch = run_git_ex(1, "config", "--get",
+
"branch." + local_branch + ".merge");
+
if (has_prefix(remote_branch, "refs/heads/tracking/")) {
+
write("Attempt to commit to remote tracking branch.\n");
+
return 1;
+
}
+
}
+
int hook() { files_to_commit = split_z(run_git("diff", "--staged", "--name-only", "-z")); attrs = GitAttributes(get_file(".gitattributes", 1)); return
-
+
check_not_tracking() |
check_attributes_staged() | check_blocker_attributes() | check_gitattributes_files(); } } /* Checks run before accepting a push */ class PreReceiveHook { inherit CommitHookUtilsRepo; enum AccessLevel { ACCESS_NONE = 0, ACCESS_BASIC = 1, ACCESS_GROUP = 2, // Create group tags.
-
ACCESS_
FULL
= 3, // rebase/delete branch, move/delete tag, etc.
+
ACCESS_
EXISTING
= 3,
//
May
be
updated to any previously existing commit.
+
ACCESS_FULL = 4,
// rebase/delete branch, move/delete tag, etc.
}; protected mapping(string:AccessLevel) groups = ([ "scratch": ACCESS_FULL, ]); protected array(string) commits_to_check = ({}); protected void parse_groups(string user) { string git_dir = get_git_dir(); groups[user] = ACCESS_FULL;
-
+
groups["tracking"] = ACCESS_EXISTING;
string group_data = Stdio.read_bytes(combine_path(git_dir, "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
githelper.git/githelper.pike:621:
} // Restore master permission in case username == groupname. groups[user] = ACCESS_FULL; } AccessLevel check_access(string ref_name, string user) { /* Return ACCESS_NONE (0) for no access, * ACCESS_BASIC (1) for basic access, and
-
* ACCESS_FULL (
2
) for full access
+
* ACCESS_FULL (
4
) for full access
* (including rebase/delete branch, and move/delete tag) */ string shortref = ref_name; sscanf(shortref, "refs/%*[^/]/%s", shortref); foreach(groups; string group; AccessLevel ac) { if (has_prefix(shortref, group + "/")) { if (!ac) { write("Access to %s denied for user %s\n", ref_name, user); } return ac;
githelper.git/githelper.pike:684:
write("Main version branches can not be created remotely.\n"); return 1; } if (access_level < ACCESS_GROUP && search(ref_name[11..], "/")>=0) { write("Common topic branch names are not allowed to contain /.\n"); return 1; } return 0; } else if (new_sha == "0"*40) { // Delete old branch
-
if (access_level < ACCESS_
FULL
) {
+
if (access_level < ACCESS_
EXISTING
) {
write("You may not delete branches which do not belong to you.\n"); return 1; } return 0; } else {
-
if (access_level >= ACCESS_
FULL
)
+
// FIXME: Ought to ensure that the commit allready exists
+
// for ACCESS_EXISTING.
+
if (access_level >= ACCESS_
EXISTING
)
/* Skip checks */ return 0; string merge_base = String.trim_all_whites(run_git("merge-base", old_sha, new_sha)); if (merge_base != old_sha) { write("Push to %s is not fast-forward.\n", ref_name); return 1; } array(string) old_depth = split_lf(run_git("rev-list", "--first-parent",