Reputation: 313
I have to mention I'm new to git before you judge me for asking (maybe) stupid question. I'm working in an environment where we have a lot of branches and one is considered the mainline. Because we have different teams working on the project, we configured jenkins to build and run tests after every commit on any branch. But here comes the problem, people commit on their branch without rebasing with the mainline so the tests fail sometimes because modifications were pushed for the mentioned tests in the mainline and people don't have the modifications on their branch. Is there any way I could configure git to reject any commit if it's not rebased with the mainline branch?
UPDATE:
I'm currently trying something like (pre-commit hook):
#!/bin/sh
if git rev-list --left-right --count mainbranch...@ | cut -f1 > 0
then
exi1
fi
but the if always returns true. The command git rev-list --left-right --count mainbranch...@ | cut -f1 > 0
should return (and it does) the number of commits that my mainbranch is ahead (if > 0 then I need to rebase).
What am I doing wrong?
Upvotes: 1
Views: 674
Reputation: 932
You appear to have a simple shell-script issue. Your command
if git rev-list --left-right --count mainbranch...@ | cut -f1 > 0
is interpreted as "run git rev-list
, pipe it to cut
, and write the output to a file named 0
", which will always succeed.
What you want is "run git rev-list
, pipe it to cut
, and compare the result to the number 0
":
if [[ "$(git rev-list --left-right --count mainbranch...@ | cut -f1)" > 0 ]]
Upvotes: 1