第一版~

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
#!/bin/zsh

temp_git_dir=project-dir
branchs=("project-name/branch1" "project-name/branch2" "project-name/branch3" "project-name/branch4" "project-name/branch5")

cd ${temp_git_dir}
current_date=$(date +%Y%m%d-%H%M%S)
current_week=$(date +%U)
current_branch=$(git branch --show-current)
merge_to=project-name/uat-week${current_week}

git stash -m "auto stash by sh date ${current_date}"

if [[ ${current_branch} != "master" ]]; then
git checkout master
fi

git pull

for branch in ${branchs}; do
echo "git pull branch ${branch}"
git checkout ${branch} && git pull
done
git checkout master

exists=$(git show-ref refs/heads/"${merge_to}")
if [ -n "$exists" ]; then
echo "${merge_to} branch exists!"
git checkout "${merge_to}"
git merge master
else
git checkout -b "${merge_to}"
echo "create new branch ${merge_to}"
fi

for branch in ${branchs}; do
echo "merge branch ${branch} into ${merge_to}"
git merge ${branch}
done

#TODO

  • 判断上一次 merge 状态,下次一次从失败处重新开始