Distributing git configuration with the code

后端 未结 4 710
迷失自我
迷失自我 2020-11-22 03:48

In trying to standardise the platform for the developers, one of my needs would be to commit the .git/config so that everybody have the same CRLF config without

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-22 04:27

    The .git/config can be overridden locally by ~/.gitconfig.

    So as part of the build, Makefile or provision script, you can propose the change for users into their ~/.gitconfig, or load local script .gitconfig via git config.

    For example, create new .gitconfig with some settings, and load it by:

    git config --local include.path "/path/to/.gitconfig"
    

    or ask users to have in their ~/.gitconfig these lines:

    [include]
        path = .gitconfig
    

    If you're using Vagrant as part of your code distribution, you may load git config from Vagrantfile by:

    system('GIT_TRACE=1 git config --local include.path "$(git rev-parse --show-toplevel)/git/gitconfig"');
    

    then commit your git config in git/gitconfig, so each time when users run provisioning of their VM, this file would be loaded automatically for their git on host machine (e.g. to enforce core.filemode to be disabled, so Windows won't have any issues with file permissions).


    To force line endings for users, you should use .gitattributes instead which should work out-of-box. Sample syntax to use Unix-like line endings (LF):

    # Drupal git normalization
    # @see https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html
    # @see https://www.drupal.org/node/1542048
    
    # Define text file attributes.
    # - Treat them as text.
    # - Ensure no CRLF line-endings, neither on checkout nor on checkin.
    # - Detect whitespace errors.
    #   - Exposed by default in `git diff --color` on the CLI.
    #   - Validate with `git diff --check`.
    #   - Deny applying with `git apply --whitespace=error-all`.
    #   - Fix automatically with `git apply --whitespace=fix`.
    
    *.css     text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2
    *.html    text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2 diff=html
    *.js      text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2
    *.json    text eol=lf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=2
    
    # Auto-detect text files, ensure they use LF (not recommended).
    #*         text=auto eol=lf
    
    # Define binary file attributes.
    # - Do not treat them as text.
    # - Include binary diff in patches instead of "binary files differ."
    *.gz      -text diff
    

提交回复
热议问题