summaryrefslogtreecommitdiff
path: root/example/example-hooks/history-must-be-merges.update.lua
diff options
context:
space:
mode:
Diffstat (limited to 'example/example-hooks/history-must-be-merges.update.lua')
-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