Reputation: 583
I have a code repository in Azure devops for pipeline builds and others. I have dev branch and a master branch. Developers push their code to dev branch and this will be merged to master branch for release. I want to check whether the code is merged with master latest before pushing the code to the DEV branch.
This can be done, by comparing both branches manually running commands. But I want to know is this possible automatically via scripts or azure repository control configurations.
Thanks in advance.
Upvotes: 0
Views: 233
Reputation: 12280
Best solution
If master was merged into dev, master will be an ancestor of dev.
Use this to test that condition directly:
if git merge-base --is-ancestor master dev; then
# master is an ancestor of dev, and was therefore merged in
fi
Reverse master and dev to test if dev was merged into master.
Slightly longer solution
git merge-base
will tell you the last merge point of two branches. If master was merged into dev, then git merge-base master dev
will be master, and if dev was merged into master, then that merge-base will be dev.
So you can use this test to check if master was merged into dev:
if [ `git merge-base master dev` == `git rev-parse master` ]; then
# master was merged into dev
else
# master was not merged into dev
fi
Use git rev-parse dev
if you want to know whether dev was merged into master.
Reference
I found the --is-ancestor
solution in this related question:
How can I tell if one commit is an ancestor of another commit (or vice-versa)?
Upvotes: 1