/
git-feature-global.sh
120 lines (108 loc) · 2.52 KB
/
git-feature-global.sh
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
#!/bin/sh
git config --global alias.feature '!sh -c "
current=`git branch | grep ^\\* | cut -f2 -d\" \" - | tail -c +10`
if [ \$1 -a \"\$1\" = \"--current\" ]
then
if [ \$current ]
then
echo \$current
fi
exit 0
fi
if [ \$1 ]
then
feature=\$1
else
read -p \"feature name: \" feature
fi
if [ -z \$feature ]
then
exit 0
elif [ `git branch | grep features/\$feature\\\$` ]
then
git checkout features/\$feature
exit 0
fi
if [ \$2 ]
then
parent=\$2
elif [ \$current ]
then
read -p \"where will this feature be merged into when it is done? \" parent
else
parent=`git branch | grep ^\\* | cut -f2 -d\" \" -`
fi
if [ -z \$parent ]
then
exit 0
fi
read -p \"this will create a feature branch \$feature to be merged into \$parent (Y/n): \" YN
if [ -z \"\$YN\" -o \"\$YN\" = \"y\" -o \"\$YN\" = \"Y\" ]
then
git config \$feature.parent \$parent
git checkout \$parent
git checkout -b features/\$feature
else
echo \"aborting...\"
exit 0
fi
" -'
git config --global alias.integrate '!sh -c "
current=`git branch | grep ^\\* | cut -f2 -d\" \" -`
if [ -n \"\$1\" -a -n \"\$2\" -a -z \"\$3\" ]
then
feature=\$1
parent=\$2
elif [ -n \"\$1\" -a -z \"\$2\" ]
then
if [ -n \"`git feature --current`\" ]
then
parent=\$1
feature=`git feature --current`
else
parent=\$current
feature=\$1
fi
elif [ -z \"\$1\" -a -n \"`git feature --current`\" ]
then
feature=`git feature --current`
parent=`git config \$feature.parent`
fi
if [ -z \"\$feature\" ]
then
read -p \"what feature are we integrating? \" feature
fi
if [ -z \"\$parent\" ]
then
read -p \"where should this feature be integrated into? \" parent
fi
if [ -z \"\$parent\" -o -z \"\$feature\" ]
then
exit 0
fi
read -p \"this will integrate \$feature into \$parent (Y/n): \" YN
if [ -z \"\$YN\" -o \"\$YN\" = \"y\" -o \"\$YN\" = \"Y\" ]
then
git checkout features/\$feature
git rebase -i \$parent
git checkout \$parent
git merge features/\$feature
git checkout \$current
else
echo \"aborting...\"
fi
exit 0
" -'
git config --global alias.finish '!sh -c "
feature=`git feature --current`
parent=`git config \$feature.parent`
if [ -z \"\$feature\" ]
then
echo \"you must be on a feature branch to use this\"
exit 1
fi
git integrate
git checkout \$parent
git branch -d features/\$feature
git config --remove-section \$feature
" -'