summaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2012-08-10 14:13:01 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2012-08-10 14:13:01 +0100
commitf2373792d326c4ce61be72b884ee74b58e4cfea3 (patch)
treec3998bfc6281f2351694fd70529c466518179696 /example
parentf9924999ac8ad3794b46e091c5f3f8b961597ba9 (diff)
downloadgitano-f2373792d326c4ce61be72b884ee74b58e4cfea3.tar.gz
EXAMPLE-HOOKS: Add history-must-be-merges.update.lua example
Diffstat (limited to 'example')
-rw-r--r--example/example-hooks/history-must-be-merges.update.lua29
1 files changed, 29 insertions, 0 deletions
diff --git a/example/example-hooks/history-must-be-merges.update.lua b/example/example-hooks/history-must-be-merges.update.lua
new file mode 100644
index 0000000..9cac773
--- /dev/null
+++ b/example/example-hooks/history-must-be-merges.update.lua
@@ -0,0 +1,29 @@
+-- history-must-be-merges.update.lua
+--
+-- Example for hooks/update.lua in a project which ensures that all
+-- branches (refs/heads/...) only ever get merge commits.
+--
+-- Copyright 2012 Daniel Silverstone <dsilvers@digital-scurf.org>
+--
+
+local repo, ref, oldsha, newsha = ...
+
+local branch = ref:match("^refs/heads/(.+)$")
+if branch then
+ log.state("Looking at commit history on: " .. branch)
+
+ local commit = repo:get(newsha)
+
+ while commit.sha ~= oldsha do
+ commit = commit.content
+ local parents = commit.parents
+ if #parents < 2 then
+ error("Detected non-merge-commit during parent walk, at " .. commit.sha)
+ end
+ commit = parents[1]
+ end
+
+ log.state("Commits between old and new sha seem to all be merge commits")
+else
+ log.state("Skipping commit history check on: " .. ref)
+end