-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateintegrationbranch
executable file
·50 lines (39 loc) · 1.14 KB
/
createintegrationbranch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/zsh
default_branch=${1:-main}
new_branch=${2:-integration}
autoload colors
colors
git fetch
git checkout $default_branch
git pull
[[ $(git branch -l 'pr-*' --merged) ]] && git branch -d $(git branch -l 'pr-*' --merged) # delete already merged PR branches
for arg in $@; do
git fpr $arg
done
own_branches=("${(f)"$(grep -v '^#' .merge)"}")
prs=(${(f)"$(git branch -l 'pr-*' | pcregrep -o1 '(pr-[\w+]+)$')"})
for pr in $prs; do
if [[ ${pr/pr-/} =~ ^[0-9]+$ ]]; then
git checkout $pr
git reset --hard origin/pr/${pr/pr-/}
fi
done
git rev-parse --quiet --verify $new_branch && (git branch -m $new_branch $new_branch.b-$(git log -1 --format=%cd --date=format-local:'%Y-%m-%d-%H%M' $new_branch) || exit) # backup old integration branch
git checkout $default_branch
git checkout -b $new_branch
echo
merged=()
failed=()
for b in $own_branches $prs; do
echo "$fg_bold[default]Merging branch $b...$reset_color"
if git merge --no-ff --no-edit $b; then
merged+=$b
else
git merge --abort
echo "$fg[red]Aborted merging branch $b$fg[default]"
failed+=$b
fi
echo
done
echo "$fg[green]Merged: $merged $fg[default]"
echo "$fg[red]Failed: $failed"