version control over visual studio formatting style

眉间皱痕 提交于 2019-12-22 12:34:30

问题


What's the way to go if I want to have a consistent style standard versioned? I want to achieve two things:

  1. Pressing ctrl-k,ctrl-f (auto indenting) formats the code based on a shared standard
  2. Stylecop runs against shared rules

What files do I have to add in my git repository to achieve this?


回答1:


You can add a pre-commit hook.

You can version in your git repo a hook script (say pre-commit.sh) at the root of your project and include the installation instructions in your README/documentation to encourage all developers use it.

Installation is nothing more than:

ln -s ../../pre-commit.sh .git/hooks/pre-commit

As the article "Tips for using a git pre-commit hook", you need, in that hook, to ensure that code that isn't part of the prospective commit isn't tested within your pre-commit script:

# pre-commit.sh
git stash -q --keep-index

# Test prospective commit
# call format, stylecop...

git stash pop -q


来源:https://stackoverflow.com/questions/26308076/version-control-over-visual-studio-formatting-style

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!