-
Notifications
You must be signed in to change notification settings - Fork 1
/
gitcheck
executable file
·178 lines (154 loc) · 3.72 KB
/
gitcheck
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
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/zsh
workspace="/home/myles/workspace"
git="/usr/bin/git"
ant="/usr/bin/ant"
dir=( "$workspace/webapp" )
svnup() {
cd $dir
echo "Running in $dir"
$git svn fetch
resp=`git svn rebase`
respcode=$?
echo $resp
if [[ respcode -ne 0 ]]; then
resp=1
while [[ $resp -ne 0 ]]; do
resp=gitmerge
done
fi
}
gitmerge() {
read res'?Run merge?(y/n): '
if [[ $res != "y" ]]; then
echo "Aborting..."
return 0
fi
resp=`git mergetool`
respcode=$?
echo $resp
read res'?Everything ok?(y/n): '
if [[ $res != "y" ]]; then
echo "Aborting..."
exit
else
echo "Trying rebase"
resp=`git rebase --continue`
echo $resp
return $?
fi
}
svndiff() {
# Get the tracking branch (if we're on a branch)
TRACKING_BRANCH=`git svn info | grep URL | sed -e 's/.*\/branches\///'`
# If the tracking branch has 'URL' at the beginning, then the sed wasn't successful and
# we'll fall back to the svn-remote config option
if [[ "$TRACKING_BRANCH" =~ URL.* ]]
then
TRACKING_BRANCH=`git config --get svn-remote.svn.fetch | sed -e 's/.*:refs\/remotes\///'`
fi
git difftool --no-prefix $(git rev-list --date-order --max-count=1 $TRACKING_BRANCH) $*
}
svncreatebranch() {
if [[ $# -ne 3 ]]
then
echo "Requires branch name and commit message."
exit
fi
cd $dir
branch=$2
message="$3"
remote_exists="false"
local_exists="false"
for remote in $(git branch -r)
do
if [[ "$branch" == "$remote" ]]
then
remote_exists="true"
fi
done
for local in $(git branch)
do
if [[ "$branch" == "$local" ]]
then
local_exists="true"
fi
done
if [[ $remote_exists == "true" || $local_exists == "true" ]]
then
echo "Branch with that name already exists (either local or remote), exiting..."
exit
else
git svn branch -n -m "$message" $branch
read res'?Continue creating branch for real?(y/n): '
if [[ $res == "y" ]]
then
$git svn branch -m "$message" $branch
echo "Switching to a new local branch that tracks the new remote branch"
$git checkout -b local/$branch $branch
fi
fi
}
svnswitchbranch() {
if [[ $# -ne 2 ]]
then
echo "Requires branch name"
exit
fi
cd $dir
branch=$2
found="false"
for remote in $(git branch -r)
do
if [[ "$branch" == "$remote" ]]
then
found="true"
fi
done
if [[ $found == "true" ]]
then
$git checkout -b $branch
else
read res'?Not an svn branch, continue?(y/n): '
if [[ $res == "y" ]]
then
$git checkout -b $branch
fi
fi
}
trim() { return $1; }
checkstatus() {
cd $dir
res=`$git status | sed -e 's/.*nothing to commit.*/true/' -e 's/# On branch master//' | tr -d '\n' `
expected="true"
if [[ $res != $expected ]]; then;
echo "Uncommitted changes $dir"
fi
}
if [[ $# -ge 1 ]]; then
case "$1" in
"status"|"st")
checkstatus
;;
"up"|"svnup")
svnup
;;
"diff")
svndiff
;;
"create-branch"|"cb")
svncreatebranch $*
;;
"switch-branch"|"sb")
svnswitchbranch $*
;;
"help")
echo "svnup, up, diff, status, st, create-branch, cb(branch-name, message), switch-branch, sb(branch-name)"
;;
esac
exit
fi
checkstatus
read res'?Continue to update? (y/n): '
if [[ $res == "y" ]]; then
svnup
fi