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 revisionBoth sides next revision
git_hooks [2017/10/19 08:40] admingit_hooks [2017/11/28 21:13] admin
Line 52: Line 52:
     done     done
 fi fi
 +</code>
 +
 +
 +Another Version 
 +
 +<code bash>
 +#!/bin/sh
 +
 +read oldrev newrev refname protocol
 +
 +#### http://api.icndb.com/jokes/random
 +
 +merges=`git diff --name-only --stat $oldrev..$newrev`
 +
 +for changed_file in `echo $merges`; do        
 +
 +        REGEX_MERGE_DEVELOP="^.do_not_merge"
 +
 +        # If $changed_file matches regex $REGEX_MERGE_DEVELOP
 +        if [[ $changed_file =~ $REGEX_MERGE_DEVELOP ]];
 +        then
 +                                    
 +            # MERGE_PREVENT_BRANCH=$(echo $changed_file | tr "_into_" "\n")
 +            MERGE_PREVENT_BRANCH=$(echo $changed_file | tr "_" "\n" | tail -1)
 +            MERGE_TO_BRANCH=$(echo $refname | tr "/" "\n" | tail -1)
 +            
 +            if [[ "$MERGE_PREVENT_BRANCH" -eq "$MERGE_TO_BRANCH" ]];
 +            then
 +                
 +                echo -e "☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️"
 +            echo -e "\e[31m"
 +            echo -e "Please do not merge '$MERGE_PREVENT_BRANCH' into any other branch "
 +            echo -e "This file prevents merging: $changed_file \e[0m"
 +            echo -e "FIX IT: git reset HEAD $changed_file"
 +            echo -e ""
 +                echo -e "☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️  ☠️"
 +                exit 1
 +            fi
 +        else
 +            exit 0
 +        fi
 +done
 +
 </code> </code>
git_hooks.txt · Last modified: 2017/12/20 02:34 by admin