githelper.git
/
githelper.pike
version
»
Context lines:
10
20
40
80
file
none
3
githelper.git/githelper.pike:566:
/* Checks run before accepting a push */ class PreReceiveHook { inherit CommitHookUtilsRepo; enum AccessLevel { ACCESS_NONE = 0, ACCESS_BASIC = 1,
-
ACCESS_
FULL
= 2, // rebase/delete branch, move/delete tag, etc.
+
ACCESS_
GROUP
= 2,
//
Create group tags.
+
ACCESS_FULL = 3,
// 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) {
githelper.git/githelper.pike:601:
if ((sizeof(fields) != 4) || (fields[0] == "")) continue; array(string) members = map(fields[3]/",", String.trim_all_whites); if (members[0] == user) { // Primary member. groups[fields[0]] = ACCESS_FULL; continue; } if (groups[fields[0]]) continue; // Already a member. if (has_value(members, user)) {
-
groups[fields[0]] = ACCESS_
BASIC
;
+
groups[fields[0]] = ACCESS_
GROUP
;
continue; } groups[fields[0]] = ACCESS_NONE; } // Restore master permission in case username == groupname. groups[user] = ACCESS_FULL; } AccessLevel check_access(string ref_name, string user)
githelper.git/githelper.pike:651:
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 %s it\n", ref_name, oldtag, (new_sha == "0"*40? "delete":"move")); return 1; } if (!sizeof(oldtag) && search(ref_name[10..], "/") >= 0) {
+
if (access_level >= ACCESS_GROUP) {
+
// Group tag and we have permission.
+
return 0;
+
}
write("Common tags are not allowed to contain /.\n"); return 1; } return 0; } int check_branch_push(string old_sha, string new_sha, string ref_name, AccessLevel access_level) { if (old_sha == "0"*40) { // New branch, check if the name is allowed... if (sscanf(ref_name, "refs/heads/%*[0-9.]%*c") < 2) { write("Main version branches can not be created remotely.\n"); return 1; }
-
if (access_level <
2
&& search(ref_name[11..], "/")>=0) {
+
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 <
2
) {
+
if (access_level <
ACCESS_FULL
) {
write("You may not delete branches which do not belong to you.\n"); return 1; } return 0; } else { if (access_level >= ACCESS_FULL) /* Skip checks */ return 0; string merge_base =