-
Notifications
You must be signed in to change notification settings - Fork 0
/
vcs
executable file
·166 lines (155 loc) · 2.88 KB
/
vcs
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
#
# Run VCS commands. Abstracts away the actual VCS being used. Currently
# available: add, remove, commit
#
# Do it for real
PRETEND="no"
# Default commit message
VCS_COMMITMSG="Forgot the commit message"
# Set usage output
USAGE="[-hp] <command>"
LONGUSAGE="\t-h\tPrint this help message
\t-p\tPretend
\t<command>\t Command to run.
\tAvailable commands:
\t\tadd <files>\tAdd file(s) to the VCS
\t\trm <files>\tRemove file(s) from the VCS and the filesystem
\t\tcommit [-h] [-m <commitmsg>] [-F <file>] [<files>]\tCommit to the VCS
\t\tup [<files>]\tUpdate files
\t\tstatus [<files>]\tGet status on files
\t\tdiff [<files>]\tDiff files
\t\tmv <source> <dest>\tmove a file
\t\trevert [<files>]\trevert to last checked in state
\t\tcp <source> <dest>\tcopy a file"
# Standard functions
source ${SCRIPTS}/functions.sh
# Parse arguments
while getopts ":hp" option; do
case ${option} in
p ) PRETEND="yes";;
h ) usage;;
\? ) usage "Invalid argument ${OPTARG}";;
* ) usage "Invalid argument ${option}";;
esac
done
if [ "${OPTIND}" != "0" ]; then
shift $((OPTIND-1))
OPTIND=1
fi
# Get command
if [ -z "$1" ]; then
usage "No command"
else
CMD="$1"
shift 1
fi
# Process command line based on command
case "${CMD}" in
add|rm)
if [ -z "$*" ]; then
usage "${CMD} needs file(s)"
fi
FILES="$@"
;;
commit)
while getopts ":hm:F:" option; do
case ${option} in
m ) VCS_COMMITMSG=${OPTARG};;
F ) VCS_COMMITFILE=${OPTARG};;
h ) usage;;
\? ) usage "Invalid argument ${OPTARG}";;
* ) usage "Invalid argument ${option}";;
esac
done
if [ "${OPTIND}" != "0" ]; then
shift $((OPTIND-1))
fi
if [ -n "$*" ]; then
FILES="$@"
fi
;;
up)
;;
status|diff|revert|annotate|log)
FILES="$@"
;;
mv|cp)
if [ -z "$1" ]; then
usage "${CMD} needs files"
fi
if [ -z "$2" ]; then
usage "${CMD} needs files"
fi
;;
*)
usage "Unknown command ${CMD}"
;;
esac
# Detect the vcs
PORTDIR="."
vcs_detect
# Run the command
case "${CMD}" in
add)
if [ "${PRETEND}" == "yes" ]; then
echo vcs_add ${FILES}
else
vcs_add ${FILES}
fi
;;
rm)
if [ "${PRETEND}" == "yes" ]; then
echo vcs_rm ${FILES}
else
vcs_rm ${FILES}
fi
;;
commit)
if [ "${PRETEND}" == "yes" ]; then
if [ -n "${VCS_COMMITFILE}" ]; then
echo "vcs_commit -F ${VCS_COMMITFILE} ${FILES}"
else
echo "vcs_commit -m \"${VCS_COMMITMSG}\" ${FILES}"
fi
else
vcs_commit ${FILES}
fi
;;
up)
if [ "${PRETEND}" == "yes" ]; then
echo vcs_update ${FILES}
else
vcs_update ${FILES}
fi
;;
status)
vcs_status ${FILES}
;;
diff)
vcs_diff ${FILES}
;;
revert)
vcs_revert ${FILES}
;;
annotate)
vcs_annotate ${FILES}
;;
log)
vcs_log ${FILES}
;;
mv)
if [ "${PRETEND}" == "yes" ]; then
echo vcs_mv ${@}
else
vcs_mv ${@}
fi
;;
cp)
if [ "${PRETEND}" == "yes" ]; then
echo vcs_cp ${@}
else
vcs_cp ${@}
fi
;;
esac