|
|
| Line 73: |
Line 73: |
| ==Git 钩子== | | ==Git 钩子== |
|
| |
|
| ===Install Pre-commit git hook=== | | ===安裝預提交 git hook=== |
| You can use git hooks to check the syntax of the file you commit and cancel the commit if something is wrong. You need '''phpcs''' command line tool for this (sudo apt-get -y install php-codesniffer). If you have '''phpcbf''' installed, you can also fix the files automatically. This is how to:
| | 您可以使用 git hooks 檢查您提交的文件的語法,並在發生錯誤時取消(或更好地自動修復)提交。 |
|
| |
|
| Go to '''/dev/setup/git/hooks''' of your local repository, copy the file '''pre-commit''' into your '''.git/hooks''' folder of the local git repository and make it executable.
| | 此文件中提供了安裝此類預提交掛鉤的說明: |
|
| |
|
| Next, you need to edit pre-commit file in .git/hooks to modify the DIRPHPCS variable to set the path of your phpcs and phpcbf tool (you can keep it empty if tools are available into your PATH).
| | https://github.com/Dolibarr/dolibarr/tree/develop/dev/setup/pre-commit |
|
| |
|
| Such hooks will work when using on command line but may also work when committing using your common IDE (it has been validated with Eclipse and VSC).
| | 此類掛鉤在命令列上使用時可以工作,但在使用通用 IDE 提交時也可以工作(它已通過 Eclipse 和 VSC 進行了驗證)。 |
|
| |
|
| Once installed, the hook will start on your next commit to re-format your code, so your code will always match the coding syntax rules. If everybody enable this hook, everybody will use the same coding syntax rule, so it is highly recommended to enable it if you can. If something is wrong in the syntax, the commit will be immediately canceled. If it can be fixed automatically, phpcbf will fix it so you just have to try the commit a second time to have it validated.
| | 安裝後,該掛鉤將在您下一次提交時啟動以重新格式化您的程式碼,因此您的程式碼將始終符合編碼語法規則。如果每個人都啟用此鉤子,則每個人都將使用相同的編碼語法規則,因此強烈建議您盡可能啟用它。如果語法有問題,提交將立即取消。如果它可以自動修復,在安裝預提交掛鉤期間安裝的 phpcbf 將修復它,因此您只需再次嘗試提交即可驗證它。 |
|
| |
|
| =[[File:Computer.png]] 可选组件= | | =[[File:Computer.png]] 可选组件= |