-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathigit.sh
More file actions
executable file
·124 lines (114 loc) · 3.4 KB
/
igit.sh
File metadata and controls
executable file
·124 lines (114 loc) · 3.4 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/bash
version=0.2.1
if [ "$1" == "-help" ]
then
printf "\e[32m \nThe little rebase tool for lazy people\n"
echo "--------------------------------------"
printf "\e[0m \nThis script will perform a rebase with the latest remote master branch, by following steps:\n"
printf "* checkout master\n"
printf "* pull changes from remote\n"
printf "* go automatically back to working branch\n"
printf "* perform rebase, if requested (with -i) also in interactive mode\n"
printf "\nOptions:\n"
printf "* -r perform rebase for current branch\n"
printf "* -i perform rebase with interactive rebase mode\n"
printf "* -a rebase all branches\n"
printf "* -m rebase and merge current branch to master using squash\n"
printf "* -d delete current branch and go to master\n"
printf "* -v print version\n"
printf " \n"
exit 1
fi
doRebase() {
if [ "$1" != "master" ]
then
printf "\e[32m\nStarting rebase ...\n\n\e[0m"
current_branch="$1"
git checkout master
git pull
git checkout $current_branch
if [ "$2" == "-i" ]
then
git rebase master -i
else
git rebase master
fi
if [ "$(git symbolic-ref HEAD --short)" == "$current_branch" ]
then
printf "\e[32m\nRebase successful! :)\n\n\e[0m"
else
printf "\e[31m\nRebase not done yet, you may have to resolve conflicts :(\n\n\e[0m"
fi
else
printf "\e[31mYou are in master branch, no need to rebase master with master! :P\n\e[0m"
fi
}
# rebase all branches
if [ "$1" == "-a" ]
then
while true; do
read -p "Are you sure you want to rebase all branches? y/n " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
starting_branch=$(git symbolic-ref HEAD --short)
branches=()
eval "$(git for-each-ref --shell --format='branches+=(%(refname))' refs/heads/)"
for branch in "${branches[@]}"; do
current_brancg=$( echo "$branch" | cut -c 12- )
doRebase "$current_branch"
done
git checkout $starting_branch
fi
# rebase and merge branch to master using squash
if [ "$1" == "-m" ]
then
printf "\e[32m\nStarting merge...\n\e[0m"
current_branch=$(git symbolic-ref HEAD --short)
doRebase "$current_branch"
git checkout master
printf "\e[32m\nNow performing merge to master with squash\n\e[0m"
git merge $current_branch --squash
printf "\e[32m\nMerge done!\nYour are in the master branch, now commit your awesome stuff and may edit the squased commit texts.. \n\e[0m"
fi
# rebase with interactive mode
if [ "$1" == "-i" ]
then
current_branch=$(git symbolic-ref HEAD --short)
doRebase "$current_branch" "$1"
fi
# rebase current branch
if [ "$1" == "-r" ]
then
current_branch=$(git symbolic-ref HEAD --short)
doRebase "$current_branch"
fi
# delete current branch and go to master
if [ "$1" == "-d" ]
then
current_branch=$(git symbolic-ref HEAD --short)
git checkout master
git branch -D "$current_branch"
printf "\e[32m\n%s has been deleted.. RIP! Your are now in master.\n\n\e[0m" $current_branch
fi
# print version
if [ "$1" == "-v" ]
then
printf "igit version %s\n" $version
fi
# no parameter: show usage
if [[ -z "$1" ]]
then
printf "\nUsage:\n\n"
echo "-r perform rebase for current branch"
echo "-i perform rebase with interactive rebase mode"
echo "-a rebase all branches"
echo "-m rebase and merge current branch to master using squash"
echo "-d delete current branch and go to master"
echo "-v print version\n"
printf " \n"
exit 1
fi