lets have following local repository commit tree when created feature branch f
develop:
master --> \ \ develop c \ \ feature f
now after sometime new features has been merged develop c
, commit tree looks this:
master --> \ \ develop c --> d --> e \ \ feature f
now want ensure not commit before pulling latest changes develop.
master --> \ \ develop c --> d --> e \ \ feature f
from have tried, 1 way push changes f
, try merge f
develop e
(now have new changes). doing throw error messages git saying develop ahead of f
.i confident can done post-hook
. but, can git pre-hook
?
if so, how , if not please suggest other way of doing it. if possible please explain commands doing?( beginner in git )
the requirement display custom message in case user tries this.
thanks in advance!!
update: working on solution looks (later script called in pre-commit hook)
tomato.sh
#!/bin/bash working_git_dir=$1 cd $working_git_dir # switch branch_to_merge branch_to_merge=$2 git checkout $branch_to_merge parent_branch=$(git show-branch | grep '*' | grep -v "$(git rev-parse --abbrev-ref head)" | head -n1 | sed 's/.*\[\(.*\)\].*/\1/' | sed 's/[\^~].*//') echo $parent_branch # in memory merging of feature branch , parent , possible conflicts git merge-tree `git merge-base fetch_head $parent_branch` fetch_head $parent_branch
how run
sh +x tomato.sh (path working_git_dir) (branch_to_merge)
how script works
it tries find parent branch (look [here][2] detail). 3 way merge using :
git merge-tree <base> <branch1> <branch2>
base -> find best-common-ancestor between current fetch_head & parent/nearest parent branch of current parent branch
branch1 -> current fetch_head
branch2 -> parent/nearest parent branch of current parent branch
this give in memory merge of remote , local branch without changing indexes.
please comment if improves script.
thanks in advance!
now want ensure not commit before pulling latest changes develop.
this isn't possible commits in git local
i think need team understanding work rebased on develop before pushing. enforce code review.
there may technological way enforce in ci.
Comments
Post a Comment