githelper.git/
githelper.pike
Branch:
Tag:
Non-build tags
All tags
No tags
2010-09-27
2010-09-27 21:51:57 by Marcus Comstedt <marcus@mc.pp.se>
eecd8a9dba01fb1aab53a1853c115225fe54a7e9 (
40
lines) (+
37
/-
3
)
[
Show
|
Annotate
]
Branch:
master
Check that tags are not moved and branches only fast-forwarded.
420:
check_gitattributes_files(); }
-
int check_push(string old_sha, string new_sha, string ref_name)
+
int check_
tag_
push(string old_sha, string new_sha, string ref_name)
{
-
if
(
old
_
sha
==
"
0
"
*40
) {
-
//
New
ref
,
maybe
check
if
the
name
is
allowed...
+
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;
+
}
+
return 0;
-
+
}
+
+
int check_branch_push(string old_sha, string new_sha, string ref_name)
+
{
+
if (old_sha == "0"*40) {
+
// New branch, maybe check if the name is allowed...
+
return 0;
} else {
-
+
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;
+
}
+
foreach(split_lf(run_git("rev-list", old_sha+".."+new_sha)), string sha) if(check_commit(sha)) return 1;
433:
} }
+
int check_push(string old_sha, string new_sha, string ref_name)
+
{
+
if (has_prefix(ref_name, "refs/tags/")) {
+
return check_tag_push(old_sha, new_sha, ref_name);
+
} else if (has_prefix(ref_name, "refs/heads/")) {
+
return check_branch_push(old_sha, new_sha, ref_name);
+
} else {
+
write("Trying to push a ref which is neither under refs/tags/ or refs/heads/...\n");
+
return 1;
+
}
+
}
+
int hook() { foreach(split_lf(Stdio.stdin->read()), string line) {