-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubversion.lib.sh
executable file
·189 lines (158 loc) · 4.63 KB
/
subversion.lib.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
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
#!/bin/bash
################################################################################
# subversion.lib.sh - Bash library functions related to Subversion
################################################################################
#
# Copyright (C) 2013 stepping stone GmbH
# Bern, Switzerland
# http://www.stepping-stone.ch
#
# Authors:
# Christian Affolter <[email protected]>
#
# Licensed under the EUPL, Version 1.1.
#
# You may not use this work except in compliance with the
# Licence.
# You may obtain a copy of the Licence at:
#
# http://www.osor.eu/eupl
#
# Unless required by applicable law or agreed to in
# writing, software distributed under the Licence is
# distributed on an "AS IS" basis,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied.
# See the Licence for the specific language governing
# permissions and limitations under the Licence.
#
################################################################################
# The path to the lib directory.
# The default value only works if not sourced or executed from within $PATH
LIB_DIR=${LIB_DIR:="$(readlink -f ${0%/*})"}
source "${LIB_DIR}/input-output.lib.sh"
# The path to the svn command
SVN_CMD="${SVN_CMD:="/usr/bin/svn"}"
test -f "${SVN_CMD}" || die "Missing svn command: '${SVN_CMD}'"
##
# Private variables, do not overwrite them
#
# Default user and password for authentication
_SVN_USER=""
_SVN_PASSWORD=""
# Default automatic conflict resolution action,
# see subversionSetConflictResolutionAction()
_SVN_CONFLICT_RESOLUTION_ACTION="postpone"
# Set default user and password to use for authentication
#
# subversionSetCredentials user password
function subversionSetCredentials()
{
_SVN_USER="${1}"
_SVN_PASSWORD="${2}"
}
# Set default conflict resolution action
#
# see http://svnbook.red-bean.com/en/1.7/svn.ref.svn.html#svn.ref.svn.sw.accept
# for a list of allowed actions.
#
# subversionSetConflictResolutionAction action
function subversionSetConflictResolutionAction()
{
_SVN_CONFLICT_RESOLUTION_ACTION="${1}"
}
# svn update
#
# Performs an svn update on the given path(s).
#
# If not given, uses default values for conflict resolution, user and password,
# see subversionSetConflictResolutionAction() and subversionSetCredentials().
# Returns the exit status of the svn command.
#
# subversionUpdate path [conflictResolutionAction [user [password]]]]
function subversionUpdate()
{
local path="${1}"
local conflictResolutionAction="${2:-"${_SVN_CONFLICT_RESOLUTION_ACTION}"}"
local user="${3:-"${_SVN_USER}"}"
local password="${4:-"${_SVN_PASSWORD}"}"
${SVN_CMD} update \
--username "${user}" \
--password "${password}" \
--no-auth-cache \
--non-interactive \
--accept "${conflictResolutionAction}" \
${path} 2> >(error -)
return $?
}
# svn add
#
# Performs an svn add on the given path(s).
# Returns the exit status of the svn command.
#
# subversionAdd path
function subversionAdd()
{
local path="${1}"
${SVN_CMD} add \
--non-interactive \
${path} 2> >(error -)
return $?
}
# svn propset
#
# Performs an svn propset on the given path(s).
# Returns the exit status of the svn command.
#
# subversionPropset path property value
function subversionPropset()
{
local path="${1}"
local property="${2}"
local value="${3}"
${SVN_CMD} propset \
--non-interactive \
"${property}" "${value}" \
${path} 2> >(error -)
return $?
}
# svn propset svn:keywords
#
# Performs an svn propset with the svn:keywords property on the given path(s).
# Sets Id and Revision as the default keywords.
# Returns the exit status of the svn command.
#
# subversionAddKeywords path [keywords]
function subversionAddKeywords()
{
local path="${1}"
local keywords="${2:-"Id Revision"}"
local property="svn:keywords"
subversionPropset "${path}" "${property}" "${keywords}"
return $?
}
# svn commit
#
# Performs an svn commit on the given path(s).
#
# If not given, uses default values for user and password, see
# subversionSetCredentials().
# Returns the exit status of the svn command.
#
# subversionCommit path message [user [password]]
function subversionCommit()
{
local path="${1}"
local message="${2}"
local user="${3:-"${_SVN_USER}"}"
local password="${4:-"${_SVN_PASSWORD}"}"
${SVN_CMD} commit \
--username "${user}" \
--password "${password}" \
--no-auth-cache \
--non-interactive \
--message "${message}" \
${path} 2> >(error -)
return $?
}