Reputation: 393
Is there is a way to check if the git branch is newly created
For example
I have a requirement that I need to identify that a given branch is brand new where there is no new commits on it, just like feature branch created above.
for example: let take bug_fix branch which is created out of master and committed some code into it. Suppose I am not aware of that commits, I should be able to fire some commands and after it, I should be able to know that it has some commits that were made after it was created out of master branch.
Ultimately I need to verify it in .gitlab-ci.yml file, is there predefined variable to check it ?
Any other alternative is also welcome. Thanks in advance for dropping by.
Upvotes: 0
Views: 702
Reputation: 1694
Gitlab specific:
# First commit of the branch.
- if: $CI_COMMIT_BEFORE_SHA == '0000000000000000000000000000000000000000'
when: on_success
If this is the creation of a new branch the $CI_COMMIT_BEFORE_SHA variable will be what you see above.
Upvotes: 0
Reputation: 534950
In the example you give, the merge-base
of master
and feature
is identical to feature
. So that gives you a template for identifying these situations.
Upvotes: 1