-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsgn
executable file
·166 lines (143 loc) · 3.72 KB
/
sgn
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/bin/bash
safeExec()
{
cmd="$1"
echo -e "\nCMD: $cmd"
echo "Press ENTER to execute this command or CTRL-C to quit"
read
eval $cmd
}
mergeOne()
{
echo -e "\nEnter a revision number:"
read rev
pristineCheck
merge_command="svn merge -c$rev $THE_TRUNK"
safeExec "$merge_command"
commit_command="svn commit -m 'Subgenie merged revision $rev from trunk'"
safeExec "$commit_command"
}
mergeRange()
{
echo -e "\nEnter the FIRST revision to merge:"
read rev1
echo -e "\nEnter the LAST revision to merge:"
read rev2
pristineCheck
let "rev1 -= 1" #SVN range syntax wants the previous rev
merge_command="svn merge -r$rev1:$rev2 $THE_TRUNK"
safeExec "$merge_command"
commit_command="svn commit -m 'Subgenie merged range $rev1:$rev2 from trunk'"
safeExec "$commit_command"
}
mergeAll()
{
pristineCheck
merge_command="svn merge $THE_TRUNK"
safeExec "$merge_command"
commit_command="svn commit -m 'Subgenie merged all revisions from trunk'"
safeExec "$commit_command"
}
pristineCheck()
{
PRISTINE=$(svn status | grep ^[!AMCDG])
if [[ -n $PRISTINE ]]; then
echo -e "\nOUCH! The working copy has local modifications!"
echo -e "What about a nice svn revert -R .? ;)"
echo
echo "Y. Yes, please. Trash 'em all!"
echo "N. No, thanks. I want to review them."
while true; do
read -s -n1 key
key=$(echo $key |tr a-z A-Z)
case "$key" in
Y)
echo -e "\nReverting the working copy to BASE.\n"
svn revert -R .
break
;;
N)
echo -e "\nSee you later, then.\n"
exit 0
;;
esac
done
fi
}
MAGIC="|sed '/^-*$/d' |sed 's/..:.*lines*//' | tr \"\n\" ' ' |sed 's/^\(.\{100\}\).*/\1/' "
echo
echo 'Subgenie'
echo '========'
if [ ! -d '.svn' ]; then
echo -e "Nice try, but current dir is not a working copy.\n"
exit 1
fi
THIS_BRANCH=$(svn info |grep '^URL' |sed 's|^URL: \([a-z]*://.*\)|\1|')
THE_TRUNK=$(echo $THIS_BRANCH |sed 's|^\(.*\)/branches/.*|\1/trunk|')
if [ $THIS_BRANCH == $THE_TRUNK ]; then
echo -e "Nice try, but you cannot merge the trunk with itself.\n"
exit 2
fi
if [[ -n $(echo $THIS_BRANCH |grep -e '^.*/branches/.*/' ) ]]; then
echo "Nice try, but this tool won't allow you to merge a subdirectory."
echo -e "You must merge a whole branch, or nothing. Sorry, mate.\n"
exit 3
fi
pristineCheck
echo -e "\nLet's make sure the working copy is up-to-date..."
svn up
echo -e '\nCurrent branch is:'
echo $THIS_BRANCH
echo 'Guess trunk is at:'
echo $THE_TRUNK
echo
ELIGIBLES=$(svn mergeinfo --show-revs eligible $THE_TRUNK)
if [ "$ELIGIBLES" == '' ]; then
echo -e "Relax, there's nothing to merge.\n"
exit 0
fi
if [[ -n $(echo $ELIGIBLES |grep \*) ]]; then
echo "Ouch! There are partially-merged revisions."
echo "Probably you merged only some files/dirs, which is not generally a good idea."
echo -e "I'm not telling anyone, but please tidy up your working copy manually.\n"
exit 4
fi
echo -e "Now listing eligible revs\n"
for rev in $ELIGIBLES; do
CMD="svn log -$rev $THE_TRUNK $MAGIC"
eval $CMD
done
echo
if [[ $1 == "-l" ]]; then exit 0; fi
echo "I can't help you unless you make a wish."
echo 'You have to say, "Genie, I want you to save my life," got it?'
echo "Okay!"
echo
echo "A. Merge everything"
echo "C. Merge a single commit"
echo "R. Merge a range of commits"
echo "Q. Let me think about it"
while true; do
read -s -n1 key
key=$(echo $key |tr a-z A-Z)
case "$key" in
A)
mergeAll
break
;;
C)
mergeOne
break
;;
R)
mergeRange
break
;;
Q)
echo -e "\nSee you later, then.\n"
exit 0
;;
esac
done
echo -e "\nThank you for choosing \"Magic Carpet\" for all your travel needs.\n"
exit 0