Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/zsh -f
- branch=$1
- tag='old|'$branch
- tag_exists()
- {
- tag=$1
- git show --oneline $tag &> /dev/null;
- }
- remake_merge()
- {
- merge=$1
- # see its parents (either TAGS or branches)
- # for TAGS map to updated branch
- # 1/ leave a tag
- oldtag="old|$merge"
- git co $merge
- tags=$(merge_parents $merge )
- # echo $tags
- typeset -a refs
- foreach t ($tags)
- {
- if git tag |grep -F $t >/dev/null;
- then
- # echo $t "is a TAG ..."
- refs[$(expr $#refs + 1)]=$(echo ${t##old|})
- elif git br |grep -F $t >/dev/null;
- then
- # echo $t "is a branch...ok"
- refs[$(expr $#refs + 1)]=$t
- else
- echo $t "is UNKNOWN" >&2
- fi
- }
- echo "MERGE $merge: " $refs
- echo " (press y)"
- read pause
- if [ "$pause" = "y" ];
- then
- ~/start_rewriting $merge
- git reset --hard $refs[1]
- git merge $refs[2,-1]
- ~/post_rewriting $merge
- fi
- # if all ok
- }
- # Find direct descendants!
- parents()
- {
- commit=$1
- # skip the 1:
- git rev-list --no-walk --parents $commit | tail -c +42
- }
- is_not_merge ()
- {
- commit=$1
- count=$(git rev-list --no-walk --parents $commit |wc --w)
- test $count = 2
- }
- # is a merge of:
- # one of parents == .
- direct()
- {
- from=$1
- to=$2
- between=$(git log --pretty=format:%d $from..$to |grep -v '^$' |wc -l)
- test $between = 1;
- }
- direct_merge()
- {
- hash=$(git rev-list --no-walk $1)
- git rev-list --no-walk --parents $commit |grep $hash > /dev/null
- # foreach parent_of $merge
- # {
- # # if it is one of the parents!
- # if direct $from $parent;
- # then
- # return 0;
- # fi
- # }
- # false
- }
- #describe merge (in terms of tags & refs):
- # given a hash: its ref:
- merge_parents()
- {
- hashes=$(parents $1)
- # git rev-list --pretty=format:%d --no-walk b40683d467a9dc85a076ec10d418e11e1eac79e6
- foreach hash ($hashes)
- {
- git rev-list --pretty=format:%d --no-walk $hash |\
- tail -n +2|sed -e 's/^ (//;s/)$//'
- # some are TAG REF ...
- # tag? git tag |grep -F
- # tag -> ref strip old|
- #
- }
- }
- # tag exists?
- # git tag -l
- if tag_exists $tag;
- then
- echo "getting all branches down from tag $tag"
- echo "the tag is on commit:"
- git log --pretty=format:%H $tag |head -n 1
- dbranches=$(git branch --no-color --contains $tag|sed -e "s/^\*\? \+//")
- setopt SH_WORD_SPLIT
- echo "need to rebase: " $dbranches
- echo '[01;32m====>[00m'
- foreach br ($dbranches)
- {
- if is_not_merge $br;
- then
- if direct $tag $br;
- then
- echo "REBASE " $br " (press y)"
- read pause
- if [ "$pause" = "y" ];
- then
- echo rebasing $br
- ~/start_rewriting $br
- git checkout $br;
- echo git rebase --onto $branch $tag
- git rebase --onto $branch $tag
- ~/post_rewriting $br
- fi
- else
- echo $br " is a NOT DIRECT descendant!"
- fi
- else
- if direct_merge $tag $br;
- then
- echo "we should remake the MERGE $br"
- remake_merge $br
- # merge_parents $br;
- else
- echo $br " is not direct descendant"
- fi
- fi
- }
- git tag -d $tag
- else
- echo "Tag $tag does not exist. no need to rebase descendants"
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement