Prevent merging any commit / code into a master

As part of the project that I am working on, we decided to develop a tool that helps development, so this should not be in production.
So I was wondering, since git is so awesome, if perhaps there is a function to prevent some files (yes, only files: this is a Magento project, and the tool we are going to develop will be in its own module, not overlap with the rest part of the application), which should be combined with the master, but should be available in other branches.
We are thinking of using git-flow if that helps. Thus, we will have a wizard from which we will create a development, from which we will create all our function branches. The idea was for this module to develop, but never merge back into the master.

Now I think something like ignoring these files (.gitignore) only in the main branch, will this work?

edit 1: project structure
I feel like I need to know more about the project structure, here it is:

+ main_folder/
    + magento/
    |---+ app/
    |   |--+ code/
    |   |  |--+ community/
    |   |  |--+ core/
    |   |  |--+ local/
    |   |     |--+ Namespace1/
    |   |        |--+ Module1/
    |   |        |--+ Module2/
    |   |     |--+ Namespace2/
    |   |        |--+ Module1/
    |   |        |--+ Module2/
    |   |--+ design/
    |   |  |--+ frontend/
    |   |     |--+ default/
    |   |        |--+ default/
    |   |           |--+ layout/
    |   |           |--+ template/
    |   +  js/
    |   +  lib/
    +  ezpublish/

the development tool module should be included in the main project (only part of the magenta) in different places, i.e. app / code / local / Namespace1 / Module3 /, app / design / frontend / layout / dev.xml , app / design / frontend / template / dev / tool.phtml and js / dev /

edit 2: submodule option
exploring @VonC answer , here is what I did:

  • in the main server:
    • git subodule add git @ github.com: path /to/submodule.git devtool
    • cd devtool
    • git checkout 123abC # submodule initial commit
    • cd ..
    • git add devtool
    • git commit -m " "
  • :
    • cd devtool
    • git checkout abc213 #submodule last commit
    • cd..
    • git devtool
    • git commit -m " "
  • :
    • touch.gitattributes
    • in.gitattributes : devtool merge=ours
    • git .gitattributes
    • git commit -m ". "

master , master checkout , ( , ).
, , - , ?

+4
3

, .

: , , , - ( ): SHA1 .
.

:

  • SHA1 master
  • <<21 >
  • devel master.
    (., , git merge?" .gitattributes.)
+11

- git hooks!

: " , "

:

git .// , ( , )
git commit -am " " // "pre-commit" hook


|-- ex.file
|-- module
|   |-- f2.php
|   |-- f3.php
|   `-- file.php
`-- xml
    |-- file.xml
    `-- file1.xml

git {.ignorefolders} , " "

/module/
/xml/file.xml
/ex.file

"/" , , dir " , "


{pre-commit} {.git/hooks}

ROOTDIR=$(git rev-parse --show-toplevel) #root folder
FILENAME="$ROOTDIR/.ignorefolders" #configuration file

if [ ! -f $FILENAME ]; then
    echo "File '.ignorefolders' not found!"
    exit 1
fi

BRANCHES=("master") # branches array to untrack this folders and files from if you want to remove this files from more than branch for example BRANCHES=("master" "branch2" "branch3")
CURRENTBRANCH=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p') #get current branch name

if [[ ! "$(declare -p BRANCHES)" =~ '['([0-9]+)']="'$CURRENTBRANCH'"' ]];then  #check if the current branch is NOT in the array of the branches
    exit 0
else
  echo "Executing pre-commit hook in $CURRENTBRANCH Branch"
fi

function removeFromGitAdd {
   PARAM="$ROOTDIR$1"
   if [ -e $PARAM ]; then
        #file or folder exist
        if [[ -n $(git ls-files $PARAM ) ]]; then
            #echo "there are files with this path added in the current commit"
            git rm --cached $PARAM -r #removing this files/folders
        else
            #echo "There is no file"
            echo ''
        fi

   fi
}
cat $FILENAME | while read LINE
do
       #echo $LINE
       removeFromGitAdd $LINE
done

:

( exit return) , !

return == > commit
exit === > commit

:

"git -add." , , ".ignorefolders", !
, " - ".

+2

git checkout <branch>,

git submodule update

, , Edit 2.

VonC gitsubmodule , SHA, .

, git submodule update . . , , , . git, , .

EDIT:

The launch git submodule updatecancels all current changes in the submodule with a commit, which is also indicated by the submodule object (in the parent repo). If you want to change the commit pointed to by the parent repo, check the correct version in the submodule, then cd ..commit the changes to the submodule object.

+2
source

Source: https://habr.com/ru/post/1502463/


All Articles