-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvc
More file actions
269 lines (249 loc) · 5.41 KB
/
vc
File metadata and controls
269 lines (249 loc) · 5.41 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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#!/bin/sh
##
# Version Control System agnostic commands.
#
# Version control systems use differing syntax for similar commands. The
# functions in this file attempt to standardize your workflow by allowing you
# to use the same commands across all supported version control systems. Your
# muscle memory will find it easier to repeat the same short commands, rather
# than typing out the long versions. Examples:
#
# Original:
# git status
# Becomes:
# st
#
# Original:
# git commit -m "Message"
# Becomes:
# ci "Message"
#
# Original:
# git pull origin master
# Becomes:
# up
#
# In addition to saving time by reducing typing, bash kit also contains history
# search on on the up arrow key. For instance, typing c and then up will step
# through all previously executed commands starting with the letter c. Removing
# the version control system command prefix for your commands makes this even
# more timesaving.
#
# To be able to remove the version control system prefix, bash kit needs to
# know what version control system you intend your commands to run under. We do
# this by setting an environment variable which can be switched using the vc
# command. Instead of switching context in your head, let bash kit to the hard
# work!
##
# Version Control System switcher.
#
# This function is used to switch the active version control system.
#
# Usage:
# vc [vcs]
#
# Examples:
# vc bzr # Switches the current VCS to bzr.
# vc # Returms the current VCS.
#
function vc () {
if [[ $# -eq 1 ]]; then
export VC=$1
fi
echo $VC
}
##
# Version Control System agnostic add.
#
# Note: git add is completely different to bzr|cvs|svn add!
#
function add () {
if [[ $# -eq 0 ]]; then
echo "usage: add <file>"
return
fi
$VC add $1
}
##
# Version Control System agnostic update.
#
function up () {
case $VC in
cvs )
cvs update -dP $*
;;
git )
git pull origin master
;;
* )
$VC update $*
;;
esac
}
##
# Version Control System agnostic commit.
#
# Usage:
# ci <message>
# Example:
# ci "Initial commit."
#
# When using git there is an extra option to automatically push the changes to
# the central server for each commit. This is helpful when working in a fast
# moving team environment where others depend on getting your commits as
# quickly as possible.
#
function ci () {
if [[ $# -lt 1 ]]; then
echo "usage: ci <message>"
return
fi
message="$1"
shift 1
$VC commit -m "$message" $*
if [[ $VC == 'git' && $VC_AUTOPUSH -eq 1 ]]; then
BRANCH=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
git push origin $BRANCH
fi
}
##
# Version Control System agnostic diff.
#
# Usage:
# dif [args]
#
# Examples:
# dif # Runs a VCS diff on the current repo.
# dif . # Runs a VCS diff on the current directory.
# dif file.ext # Runs a VCS diff on a specific file.
#
# Any arguments specified are passed directly to the current VCS.
#
function dif () {
if [[ $VC == 'cvs' ]]; then
cvs diff $CVS_DIFF_OPTIONS
else
$VC diff $*
fi
}
##
# Version Control System agnostic status.
#
# Usage:
# st [args]
#
function st () {
$VC status $*
}
##
# Version Control System agnostic blame.
#
# Usage:
# blame [args]
#
function blame () {
if [[ $VC == 'bzr' ]]; then
$VC blame --all $*
else
$VC blame $*
fi
}
##
# Function for running a merge commit.
#
# It is common to merge one branch into another on a regular basis. This
# function saves a bit of typing when doing such merged repeatedly.
#
# Usage:
# merged <branch>
#
# Example:
# merged trunk # Runs, for example, bzr commit -m "Merged from trunk."
#
function merged () {
if [[ $# -lt 1 ]]; then
echo "usage: merged <branch>"
return
fi
$VC commit -m "Merged from $1"
}
##
# Displays the commit log.
#
function log () {
$VC log
}
##
# VCS agnositic tag.
#
function tag () {
$VC tag
}
##
# Evaluate the type of Version Control System used for the current directory.
#
# This function was created to automatically switch version control systems
# but if not currently being used for this purpose.
#
function vc_evaluate () {
if vc_is_git; then
echo "This is a git repo."
return
fi
if vc_is_bzr; then
echo "This is a bzr repo."
return
fi
if vc_is_svn; then
echo "This is an svn repo."
return
fi
if vc_is_cvs; then
echo "This is a cvs repo."
return
fi
echo "Cannot determine VCS. This directory does not seem to be under version control."
}
function vc_is_git () {
git branch &>/dev/null
}
function vc_is_bzr () {
bzr status &>/dev/null
}
function vc_is_svn () {
svn info &>/dev/null
}
function vc_is_cvs () {
ls CVS &>/dev/null
}
##
# Commit using Drupal's standard message format.
#
# Example: "Issue #1234 by username: Messsage."
#
function cit () {
if [[ -z "$1" ]]; then
echo "usage: cit <message>"
fi
GIT_USER=$(git config github.user)
TICKET=$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e "s/* $BRANCH_NAME_PREFIX\(.*\)/\1/" | tr '[a-z]' '[A-Z]')
ci "Issue $TICKET_PREFIX$TICKET by $GIT_USER: $1"
}
##
# Checkout a branch in the form ticket-1234.
#
function cot () {
if [[ -z "$1" ]]; then
echo "usage: cot EX-123"
return
fi
TICKET=$(echo $1 | tr '[A-Z]' '[a-z]')
git checkout $BRANCH_NAME_PREFIX$TICKET
}
##
# Push to origin <current branch>.
#
function push () {
BRANCH=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
git push origin $BRANCH $@
}