How can we implement server-side hooks, or any similar solution, to restrict git push into git server?
For example, we want to disable push of commits containing *.class files.
How can we implement server-side hooks, or any similar solution, to restrict git push into git server?
For example, we want to disable push of commits containing *.class files.
I don't think Azure DevOps uses hooks.
You can use Branch Policies to make use of an external validation service (as I understand it this uses web hooks).
Additional: the status of this User Voice request indicates the above is the official answer.
But maybe the simple case would be .gitignore
and code reviews?
What I do is using build option together with policies in Azure DevOps. This is my azure-pipelines.yml
file:
---
trigger:
branches:
exclude:
- '*'
pool:
vmImage: 'ubuntu-latest'
steps:
- script: sudo apt-get install python3-pip
displayName: 'Install Python PIP'
- script: sudo apt-get install python3-setuptools
condition: succeeded()
displayName: Install Python SetupTools
- script: sudo pip3 install -r requirements.txt
condition: succeeded()
displayName: Install Python PIP Packages
- task: PythonScript@0
inputs:
scriptSource: filePath
scriptPath: hooks/lint_checker.py
pythonInterpreter: python3
condition: succeeded()
displayName: Lint Checker
I use this solution, that work properly and automatically for all users.
A combination of local git hooks
and Pre-Build events
in the csproj
that check if there is a pre-commit hook
in the .git\hooks
and if not, copy it from hooks folder that placed in the repo
Implementation:
In my repo there is hooks folder that contains 2 files:
the setup-hooks:
@echo off
echo Current location is: %cd%
:: Check if the .git/hooks directory exists
if not exist .git\hooks mkdir .git\hooks
:: Copy your hook scripts to the .git/hooks directory
copy hooks\pre-commit .git\hooks\pre-commit
echo Git hooks have been set up.
This can be achieved with a branch policy with a path filter on it. You could add a build pipeline with some powershell that returns a failed exit code.
© 2022 - 2025 — McMap. All rights reserved.
.gitignore
file. – Pontiff