skip to Main Content

Few of my team members sometimes commit code without building project/solution which gives error to other team members when they get latest and build project.

Example:-

Error in code Error in Code

Still commit option is enable in Visual Studio Commit option enable

So I want to prevent this scenario by some way like developer should not be able to commit their code until project build successfully in visual studio.

I have already gone through different settings available for GIT in Visual Studio, but can’t find any setting for this scenario.

I have also checked in DevOps for different available Repository Policies, but non of them is useful in this scenario:

Repository Policies

Any one have any idea to prevent this type of commit (with build error in project)?

2

Answers


  1. That is what CI (continuous integration) is for. You set up a specific server that runs the build after every change and reports success or failure. Most of the time, you would set it up to run on pull requests, and allow that these only be merged on a successful build.

    You didn’t specify what tools you’re using other than VS (which is not really relevant here, as you care on the state of the committed code, not how it was written). On Github for instance, you can get such automatic builds for free, they’re called "Github Actions".

    Login or Signup to reply.
  2. Git has no knowledge whatsoever of what is being committed, and AFAIK doing git add followed by git commit can not be restricted or be made conditional.

    In theory an IDE would be able to do so for its own menu options, but I am not aware of any IDE (e.g. VS or Rider) that offers such features, possibly because it would be totally pointless given that there is always the Git CLI "backdoor" to do it anyway.

    The next best thing that IS possible is to do it on a PR level: a PR can be blocked from merging if the CI-build failed for the PR branch, see e.g. How to block the merge of Current PR if the previous CI build is failed and it should pass the PR if the previous build is successful?

    (and train, guide and coach your team in doing the right thing instead of messing around…)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search