{"id":611,"date":"2015-07-13T20:53:17","date_gmt":"2015-07-13T15:23:17","guid":{"rendered":"http:\/\/techtwaddle.net\/?p=611"},"modified":"2015-07-13T20:56:30","modified_gmt":"2015-07-13T15:26:30","slug":"branch-policies-in-visual-studio-online","status":"publish","type":"post","link":"https:\/\/techtwaddle.co.in\/blog\/2015\/07\/13\/branch-policies-in-visual-studio-online\/","title":{"rendered":"Branch Policies in Visual Studio Online"},"content":{"rendered":"<p>Branch policies in VSO allow you to set certain rules against branches in your Visual Studio Online git repos. They are more or less like gated check-ins which TFS has had since forever. Visual Studio Online supports the below policies by default:<\/p>\n<ul>\n<li>Changes must be submitted to a branch only via Pull Requests<\/li>\n<li>A build must complete successfully before changes can be merged to the destination branch<\/li>\n<li>Add certain reviewers if the pull request modifies files in certain paths in the repo<\/li>\n<\/ul>\n<p>To know more details on the complete workflow involving pull requests on visual studio online, check this excellent post <a title=\"http:\/\/blogs.msdn.com\/b\/visualstudioalm\/archive\/2014\/06\/10\/git-pull-request-visual-studio-online.aspx\" href=\"http:\/\/blogs.msdn.com\/b\/visualstudioalm\/archive\/2014\/06\/10\/git-pull-request-visual-studio-online.aspx\">http:\/\/blogs.msdn.com\/b\/visualstudioalm\/archive\/2014\/06\/10\/git-pull-request-visual-studio-online.aspx<\/a><\/p>\n<p><strong>Setting up branch policies<\/strong><\/p>\n<p>To setup branch policies login to your visual studio online account and navigate to the team project, which has the git repo you want to set the policy on. You will need to have administrator privileges on the team project to setup the policy. After you\u2019ve navigated to your team project, click on the settings wheel icon on the top right corner, this will take you to the admin panel of your team project. Select the \u2018version control\u2019 tab, and on the left rail select the branch you want to set the policy on (<em>master branch in my case<\/em>), and click on \u2018branch policies\u2019 tab. Refer the figure below, the click points are highlighted in yellow.<\/p>\n<p><a href=\"https:\/\/www.techtwaddle.co.in\/blog\/wp-content\/uploads\/2015\/07\/image23.png\"><img decoding=\"async\" loading=\"lazy\" title=\"image\" style=\"border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline\" border=\"0\" alt=\"image\" src=\"https:\/\/www.techtwaddle.co.in\/blog\/wp-content\/uploads\/2015\/07\/image_thumb23.png\" width=\"675\" height=\"424\" \/><\/a>&#160; <br \/>&#160;<\/p>\n<p>Under \u2018Automatically build pull requests\u2019, select both check boxes. You will need to provide a build definition here which VSO will queue every time a pull request is submitted or updated with a new commit. The second check box, \u2018Block the merge\u2019, is actually optional, if you want to allow the merge even on build break, you can uncheck this. Though I\u2019m not sure why you\u2019d want to do that.<\/p>\n<p>The next section, \u2018Code review requirements\u2019, allows you to control how changes can be submitted to master branch. The first check box, \u2018Require code reviews using pull request\u2019, ensures that any changes to master happen only via pull requests and no one is able to push their changes directly to master. \u2018Allow users to approve their own changes\u2019, allows to you add yourself as one of the reviewers and approve the changes, which is nuts really :-)<\/p>\n<p>The last option, \u2018Add a new path\u2019, enables you to add reviewers optionally depending on the files involved in the commits. For scenarios where you really want Dave C to look at the changes if anyone modifies files under \\kernel\\base. It has support for wild chars as well.<\/p>\n<p>After the policies are set, when someone tries to push their changes directly to master, they see this:<\/p>\n<p><a href=\"https:\/\/www.techtwaddle.co.in\/blog\/wp-content\/uploads\/2015\/07\/image24.png\"><img decoding=\"async\" loading=\"lazy\" title=\"image\" style=\"border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline\" border=\"0\" alt=\"image\" src=\"https:\/\/www.techtwaddle.co.in\/blog\/wp-content\/uploads\/2015\/07\/image_thumb24.png\" width=\"366\" height=\"186\" \/><\/a> <\/p>\n<p><a href=\"https:\/\/www.techtwaddle.co.in\/blog\/wp-content\/uploads\/2015\/07\/image25.png\"><img decoding=\"async\" loading=\"lazy\" title=\"image\" style=\"border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline\" border=\"0\" alt=\"image\" src=\"https:\/\/www.techtwaddle.co.in\/blog\/wp-content\/uploads\/2015\/07\/image_thumb25.png\" width=\"692\" height=\"125\" \/><\/a> <\/p>\n<p>So what you need to do now, is move your changes to a feature branch, push that branch to server and create a pull request to merge the changes to master. This workflow is explained in the <a href=\"http:\/\/blogs.msdn.com\/b\/visualstudioalm\/archive\/2014\/06\/10\/git-pull-request-visual-studio-online.aspx\">link<\/a> shared above.<\/p>\n<p>Now let\u2019s say, the feature branch was pushed and a pull request was created, but the change list has a silly syntax error. You will see the branch policies show up in the right rail and a build will be queued for verification.<\/p>\n<p><a href=\"https:\/\/www.techtwaddle.co.in\/blog\/wp-content\/uploads\/2015\/07\/image26.png\"><img decoding=\"async\" loading=\"lazy\" title=\"image\" style=\"border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline\" border=\"0\" alt=\"image\" src=\"https:\/\/www.techtwaddle.co.in\/blog\/wp-content\/uploads\/2015\/07\/image_thumb26.png\" width=\"528\" height=\"91\" \/><\/a> <\/p>\n<p><a href=\"https:\/\/www.techtwaddle.co.in\/blog\/wp-content\/uploads\/2015\/07\/image27.png\"><img decoding=\"async\" loading=\"lazy\" title=\"image\" style=\"border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline\" border=\"0\" alt=\"image\" src=\"https:\/\/www.techtwaddle.co.in\/blog\/wp-content\/uploads\/2015\/07\/image_thumb27.png\" width=\"252\" height=\"393\" \/><\/a> <\/p>\n<p>Since the pull request had a syntax error, the build will fail and attempting to merge the changes to master will be blocked.<\/p>\n<p><a href=\"https:\/\/www.techtwaddle.co.in\/blog\/wp-content\/uploads\/2015\/07\/image28.png\"><img decoding=\"async\" loading=\"lazy\" title=\"image\" style=\"border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline\" border=\"0\" alt=\"image\" src=\"https:\/\/www.techtwaddle.co.in\/blog\/wp-content\/uploads\/2015\/07\/image_thumb28.png\" width=\"251\" height=\"202\" \/><\/a> <\/p>\n<p><a href=\"https:\/\/www.techtwaddle.co.in\/blog\/wp-content\/uploads\/2015\/07\/image29.png\"><img decoding=\"async\" loading=\"lazy\" title=\"image\" style=\"border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline\" border=\"0\" alt=\"image\" src=\"https:\/\/www.techtwaddle.co.in\/blog\/wp-content\/uploads\/2015\/07\/image_thumb29.png\" width=\"513\" height=\"140\" \/><\/a> <\/p>\n<p>The next step is to fix the build failure, add a commit to the pull request and make sure you have at least one approval from reviewers. As soon as you push your local branch to server, a new build will be queued automatically and the status updated.<\/p>\n<p><a href=\"https:\/\/www.techtwaddle.co.in\/blog\/wp-content\/uploads\/2015\/07\/image30.png\"><img decoding=\"async\" loading=\"lazy\" title=\"image\" style=\"border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline\" border=\"0\" alt=\"image\" src=\"https:\/\/www.techtwaddle.co.in\/blog\/wp-content\/uploads\/2015\/07\/image_thumb30.png\" width=\"241\" height=\"177\" \/><\/a> <\/p>\n<p>To enhance this even further, you can improve your build definition by, let\u2019s say, adding a unit test build step and a code analysis build step, to ensure that all unit tests pass, before the pull request can be accepted and merged into master.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Branch policies in VSO allow you to set certain rules against branches in your Visual Studio Online git repos. They are more or less like gated check-ins which TFS has had since forever. Visual Studio Online supports the below policies by default: Changes must be submitted to a branch only via Pull Requests A build &hellip; <a href=\"https:\/\/techtwaddle.co.in\/blog\/2015\/07\/13\/branch-policies-in-visual-studio-online\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Branch Policies in Visual Studio Online<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[10,6,21,22],"tags":[23],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p1ktFF-9R","_links":{"self":[{"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/posts\/611"}],"collection":[{"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/comments?post=611"}],"version-history":[{"count":2,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/posts\/611\/revisions"}],"predecessor-version":[{"id":613,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/posts\/611\/revisions\/613"}],"wp:attachment":[{"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/media?parent=611"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/categories?post=611"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/tags?post=611"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}