githelper.git/
githelper.pike
Branch:
Tag:
Non-build tags
All tags
No tags
2010-10-02
2010-10-02 15:11:13 by Marcus Comstedt <marcus@mc.pp.se>
e6367fdc474f9c33e79e6ddb877b77e9de752d64 (
35
lines) (+
35
/-
0
)
[
Show
|
Annotate
]
Branch:
master
Check dates of commits.
88:
return run_git("cat-file", "blob", blob); }
+
string check_commit_timestamps(string commit)
+
{
+
int cct, cat, pct, pat;
+
string parents;
+
int sysclock = time() + 60;
+
if(3 != sscanf(run_git("log", "-n", "1", "--format=%ct %at %P", commit),
+
"%d %d %s\n", cct, cat, parents))
+
fail("Unexpected output from git log");
+
if (cat > sysclock)
+
return "Author time is in the future";
+
if (cct > sysclock)
+
return "Commit time is in the future";
+
if (cat > cct)
+
return "Author time is later than commit time";
+
foreach(parents/" ", string parent) {
+
if(2 != sscanf(run_git("log", "-n", "1", "--format=%ct %at", parent),
+
"%d %d", pct, pat))
+
fail("Unexpected output from git log");
+
if (cct < pct)
+
return "Commit time is before that of parent "+parent;
+
}
+
return 0;
+
}
+
class GitAttributes { enum {
416:
files_to_commit = split_z(run_git("diff", "--name-only", "-z", sha, sha+"^")); attrs = GitAttributes(get_file(".gitattributes", 1));
+
string ts_test = check_commit_timestamps(sha);
+
if (ts_test) {
+
write("Invalid timestamps: %s\n", ts_test);
+
return 1;
+
}
return check_blocker_attributes() || check_gitattributes_files(); }
504:
GitAttributes(get_committed_file("HEAD", ".gitattributes", 1)); foreach(committed_files, string filename) cleanup(filename, attrs->checkattr(filename));
+
string ts_test = check_commit_timestamps("HEAD");
+
if (ts_test) {
+
write("NOTICE: Your commit has invalid timestamps: %s\n", ts_test);
+
write("Please amend it before pushing.\n");
+
}
return 0; } }