githelper.git/
githelper.pike
Branch:
Tag:
Non-build tags
All tags
No tags
2010-09-25
2010-09-25 14:43:41 by Marcus Comstedt <marcus@mc.pp.se>
08686fe2de22f5763103bc1fa1e4babc4c40261f (
35
lines) (+
34
/-
1
)
[
Show
|
Annotate
]
Branch:
master
Handle foreign_idents.
57:
class PreCommitHook {
+
string get_staged_file(string filename)
+
{
+
string sha;
+
if (2 != sscanf(run_git("ls-files", "--stage", "--", filename),
+
"%*o %s ", sha))
+
fail("Unable to parse output from git ls-files...\n");
+
return run_git("cat-file", "blob", sha);
+
}
+
int check_attributes_staged() { // We don't allow .gitattributes to differ between wt and index,
70:
} }
+
int check_ident(string filename)
+
{
+
string data = get_staged_file(filename);
+
int p=0;
+
while ((p = search(data, "$Id", p))>=0) {
+
if (data[p..p+3] != "$Id$") {
+
write("File %s contains an expanded ident.\n"
+
"Try 'git reset %s; git add %s', "
+
"or remove the ident manually.\n",
+
@({filename})*3);
+
return 1;
+
}
+
p += 4;
+
}
+
return 0;
+
}
+
int check_blocker_attributes(array(string) files_to_commit) {
-
constant attrs_to_check = ({ "foreign_ident", "block_commit" });
+
constant attrs_to_check = ({ "foreign_ident", "block_commit"
,
"ident"
});
foreach(run_git("check-attr", @attrs_to_check, "--", @files_to_commit) / "\n" - ({""}), string line) {
89:
write("File %s is blocked from committing: %s\n", filename, replace(value, "-", " ")); return 1;
+
case "ident":
+
if (value == "unset")
+
break;
+
if (check_ident(filename))
+
return 1;
+
break;
} } }