User Tools

Site Tools


git_hooks

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
git_hooks [2017/12/20 01:46] admingit_hooks [2017/12/20 02:31] – [How it works] admin
Line 3: Line 3:
 ===== pre-receive Hook (Server-Side) ===== ===== pre-receive Hook (Server-Side) =====
  
-This is a hook i use along with Gitlab. Its global and will be triggerd for all repositories when data ist send to the server.+This is a hook i use along with Gitlab. Its global and will be triggerd for all repositories when data is send to the server. When data is send to the server old and new revs will be compared depending on the changed files. If the changed files contain a file named <code>.do_not_merge__WHAT-EVER-YOUR-BRANCH-IS</code> the hook will check if the branch you are pushing to **is not equal** to **WHAT-EVER-YOUR-BRANCH-IS** and will refuse to merge. 
 + 
 +In case **WHAT-EVER-YOUR-BRANCH-IS** is equal to the branch you try to push to the merge will not be refuse. This is because we want to be able to create the .do_not_merge file where necessary. 
 + 
 +==== Setup ==== 
 For Gitlab Omnibus installations place ''pre-receive'' file in this Folder (if it does not exist, create it) For Gitlab Omnibus installations place ''pre-receive'' file in this Folder (if it does not exist, create it)
 ''/opt/gitlab/embedded/service/gitlab-shell/hooks/pre-receive.d/'' ''/opt/gitlab/embedded/service/gitlab-shell/hooks/pre-receive.d/''
  
 Make sure the file ist executable using ''chmod +x pre-receive'' Make sure the file ist executable using ''chmod +x pre-receive''
 +
 +==== How it works ====
 +
 +The branch you do not want to be merged in any other branch create a file named <code>.do_not_merge__THE-BRANCH-NAME</code>
 +Make sure **THE-BRANCH-NAME** its exactly the same name as the Branch.
 +
 +Given you have the branch ''develop'' and want to avoid merge into any other branch, simply create a file named <code>.do_not_merge__develop</code>
 +
 +==== Expected output in CLI ====
 +
 +{{::hook-pre-receive-acoid-merge.png?800|}}
 +==== The Hook ====
  
 <code ruby pre-receive> <code ruby pre-receive>
Line 33: Line 50:
 hash_to = hash[1] hash_to = hash[1]
 @branch = hash[2] @branch = hash[2]
- 
-puts @branch 
  
 ################# #################
Line 69: Line 84:
 changed_files = `git diff --name-only --stat #{hash_from}..#{hash_to}`.chop changed_files = `git diff --name-only --stat #{hash_from}..#{hash_to}`.chop
 do_not_merge = changed_files.split(/\n/) do_not_merge = changed_files.split(/\n/)
- 
-puts changed_files 
  
 ################################################## ##################################################
git_hooks.txt · Last modified: 2017/12/20 02:34 by admin