RSS

Tag Archives: git

GIT: allow push to master only if build succeeds

It may be a requirement of companies, that the master and develop branch contains only code that is always compilable. Therefore we need to ensure that every push, or merge on a master branch results not in breaking the build of the application. This can be achieved with git-hook file that has the Name pre-commit and is copied into .git\hooks directory.

#!/bin/sh
branch=$(git rev-parse --abbrev-ref HEAD)

if [ "master" != "$branch" ] && [ "develop" != "$branch" ]; then
    exit 0;
fi

echo "To commit on a master or develop branch we need to check whether msbuild compiles successful."

"C:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe" /consoleloggerparameters:"ErrorsOnly;PerformanceSummary"
status=$?

if [ "$status" != "0" ]; then
    echo "Build failed. If you publish to the $branch branch you should ensure that the solution builds correctly"
fi
exit $status
 
Leave a comment

Posted by on December 18, 2014 in C-Sharp, Git

 

Tags:

GIT: push every commit immediately to origin

If I am working not on my primary PC I sometimes forget to push commits to the origin remote. Therefore next day I am in company I miss commits that are local on the other PC. To avoid that problem I wrote a git-hook that pushes every commit instantly to the origin-remote.

For this you need to create the file post-commit with following content

#!/bin/sh
#With this git-hook every commit is immeditely pushed to origin

branch=$(git rev-parse --abbrev-ref HEAD)
echo Pushing commit to origin/$branch
git push -u origin $branch

Save the file to the .git\hooks directory. Now after each git commit the commit is pushed to the remote.

 
Leave a comment

Posted by on December 17, 2014 in Git

 

Tags: