This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
git_hooks [2017/10/17 08:01] – admin | git_hooks [2017/12/20 02:16] – [How it works] admin | ||
---|---|---|---|
Line 4: | Line 4: | ||
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 ist send to the server. | ||
- | For Gitlab Omnibus installations place ' | ||
- | / | ||
- | Make sure the file ist executable using 'chmod +x pre-receive' | + | ==== Setup ==== |
- | <code bash pre-receive> | + | For Gitlab Omnibus installations place '' |
- | #!/bin/sh | + | '' |
- | read oldrev newrev refname | + | Make sure the file ist executable using '' |
- | ## EXAMPLE COMMAND: git log --oneline --merges 1bcca583df49bab1388a64730d1647785b3e9b8d..84da95ea03859df818ae23370f83cc80b6ce3972 | + | ==== How it works ==== |
- | ################## | + | |
- | merges=`git log --oneline | + | The branch you do not want to be merged in any other branch create a file named < |
+ | Make sure **THE-BRANCH-NAME** its exactly the same name as the Branch. | ||
- | echo ----------$(" | + | Given you have the branch '' |
- | readarray -t y <<< | + | ==== The Hook ==== |
- | for i in " | + | <code ruby pre-receive> |
- | do | + | # |
- | echo -e " | + | # Fix the PATH so that gitlab-shell can find git-upload-pack and friends. |
- | | + | ENV['PATH'] = '/opt/ |
- | echo -e " | + | |
- | exit 1 | + | |
- | done | + | |
- | </code> | + | |
- | ===== pre-commit Hook ===== | + | require ' |
+ | require ' | ||
+ | require ' | ||
- | Executed when running "git commit" | + | ################### |
+ | # General variables | ||
+ | ################### | ||
+ | refs = $stdin.read | ||
+ | key_id = ENV.delete(' | ||
+ | proto = $stdin | ||
+ | protocol = ENV.delete(' | ||
+ | repo_path = Dir.pwd | ||
+ | gl_repository = ENV[' | ||
- | <code bash pre-commit> | + | # Read given hashes |
- | #!/bin/sh | + | hash = refs.split(' |
+ | hash_from = hash[0] | ||
+ | hash_to = hash[1] | ||
+ | @branch = hash[2] | ||
- | # LOCATION: MagentoRoot/ | + | ################# |
- | mageConfig=' | + | # Colorize output |
+ | ################# | ||
+ | class String | ||
+ | def red; " | ||
+ | def green; | ||
+ | def blue; " | ||
+ | end | ||
- | # USE MAGNTOs ROOT DIRECTORY | + | ########################## |
- | sqlStorage='/root/hook/mysql_structure.sql' | + | # Pull a Chuck Norris Joke |
+ | ########################## | ||
+ | def get_joke(author | ||
+ | begin | ||
+ | plain_uri = 'http://api.icndb.com/jokes/ | ||
+ | url = URI.parse(plain_uri) | ||
+ | req = Net:: | ||
+ | |||
+ | res = Net:: | ||
+ | http.request(req) | ||
+ | } | ||
+ | joke = CGI.unescapeHTML(JSON.parse(res.body)['value' | ||
+ | |||
+ | rescue StandardError | ||
+ | joke = "Chuck Norris never sleeps? Well, even Chuck Norris needs a power nap every once in a while ..." | ||
+ | end | ||
+ | |||
+ | return joke | ||
+ | end | ||
- | # WARNING: cat IS CALLED FOR EACH VARIABLE | + | # Get changed files between hashes |
- | host=$(cat ${mageConfig} | sed -n '/< | + | changed_files |
- | username=$(cat ${mageConfig} | sed -n '/< | + | do_not_merge |
- | password=$(cat ${mageConfig} | sed -n '/< | + | |
- | dbname=$(cat ${mageConfig} | sed -n '/< | + | |
- | echo '' | + | ################################################## |
- | echo '--> EXPORT SQL STRUCTURE <--' | + | # Check if this is the .do_not_merge__ORIGIN Branch |
- | echo $host | + | ################################################## |
- | echo $username | + | def is_not_origin_branch(origin_branch) |
- | echo $password | + | current_branch = @branch.split(/ |
- | echo $dbname | + | origin_branch = origin_branch.split(/ |
- | echo ' | + | return current_branch != origin_branch |
- | echo '' | + | end |
+ | |||
+ | ###################################### | ||
+ | # Decide whether to ban or not to ban | ||
+ | ###################################### | ||
+ | do_not_merge.each do |file| | ||
+ | if (file[/ | ||
+ | if(is_not_origin_branch(file)) | ||
+ | puts " | ||
+ | puts get_joke().blue | ||
+ | puts "" | ||
+ | puts "The file #{file} stops you from pushing your changes to remote." | ||
+ | puts "You don't want to commit your changes done in DO_NOT_MERGE Branch to master or any other Branch." | ||
+ | puts "" | ||
+ | puts "To reset your branch use 'git reset --hard origin/# | ||
+ | puts " | ||
+ | exit 1 | ||
+ | end | ||
+ | end | ||
+ | end | ||
- | # EXPORT SQL STRUCTURE | ||
- | mysqldump -d -h $host -u $username -p$password $dbname > $sqlStorage | ||
- | </ |