@ -78,6 +78,13 @@ options:
version_added : " 1.6 "
version_added : " 1.6 "
description :
description :
- If C ( yes ) , do export instead of checkout / update .
- If C ( yes ) , do export instead of checkout / update .
switch :
required : false
default : " yes "
choices : [ " yes " , " no " ]
version_added : " 1.6 "
description :
- If C ( no ) , do not call svn switch before update .
'''
'''
EXAMPLES = '''
EXAMPLES = '''
@ -103,7 +110,7 @@ class Subversion(object):
self . password = password
self . password = password
self . svn_path = svn_path
self . svn_path = svn_path
def _exec ( self , args ):
def _exec ( self , args , check_rc = True ):
bits = [
bits = [
self . svn_path ,
self . svn_path ,
' --non-interactive ' ,
' --non-interactive ' ,
@ -115,8 +122,20 @@ class Subversion(object):
if self . password :
if self . password :
bits . extend ( [ " --password " , self . password ] )
bits . extend ( [ " --password " , self . password ] )
bits . extend ( args )
bits . extend ( args )
rc , out , err = self . module . run_command ( bits , check_rc = True )
if check_rc :
return out . splitlines ( )
rc , out , err = self . module . run_command ( bits , check_rc )
return out . splitlines ( )
else :
rc , out , err = self . module . run_command ( bits , check_rc )
return rc
def is_svn_repo ( self ) :
''' Checks if path is a SVN Repo. '''
rc = self . _exec ( [ " info " , self . dest ] , check_rc = False )
if rc == 0 :
return True
else :
return False
def checkout ( self ) :
def checkout ( self ) :
''' Creates new svn working directory if it does not already exist. '''
''' Creates new svn working directory if it does not already exist. '''
@ -153,8 +172,9 @@ class Subversion(object):
def has_local_mods ( self ) :
def has_local_mods ( self ) :
''' True if revisioned files have been added or modified. Unrevisioned files are ignored. '''
''' True if revisioned files have been added or modified. Unrevisioned files are ignored. '''
lines = self . _exec ( [ " status " , " --quiet " , self . dest ] )
lines = self . _exec ( [ " status " , " --quiet " , " --ignore-externals " , self . dest ] )
# The --quiet option will return only modified files.
# The --quiet option will return only modified files.
# Has local mods if more than 0 modifed revisioned files.
# Has local mods if more than 0 modifed revisioned files.
return len ( filter ( len , lines ) ) > 0
return len ( filter ( len , lines ) ) > 0
@ -183,6 +203,7 @@ def main():
password = dict ( required = False ) ,
password = dict ( required = False ) ,
executable = dict ( default = None ) ,
executable = dict ( default = None ) ,
export = dict ( default = False , required = False , type = ' bool ' ) ,
export = dict ( default = False , required = False , type = ' bool ' ) ,
switch = dict ( default = True , required = False , type = ' bool ' ) ,
) ,
) ,
supports_check_mode = True
supports_check_mode = True
)
)
@ -195,6 +216,7 @@ def main():
password = module . params [ ' password ' ]
password = module . params [ ' password ' ]
svn_path = module . params [ ' executable ' ] or module . get_bin_path ( ' svn ' , True )
svn_path = module . params [ ' executable ' ] or module . get_bin_path ( ' svn ' , True )
export = module . params [ ' export ' ]
export = module . params [ ' export ' ]
switch = module . params [ ' switch ' ]
os . environ [ ' LANG ' ] = ' C '
os . environ [ ' LANG ' ] = ' C '
svn = Subversion ( module , dest , repo , revision , username , password , svn_path )
svn = Subversion ( module , dest , repo , revision , username , password , svn_path )
@ -208,7 +230,7 @@ def main():
svn . checkout ( )
svn . checkout ( )
else :
else :
svn . export ( force = force )
svn . export ( force = force )
elif os. path . exists ( " %s /.svn " % ( dest , ) ) :
elif svn. is_svn_repo ( ) :
# Order matters. Need to get local mods before switch to avoid false
# Order matters. Need to get local mods before switch to avoid false
# positives. Need to switch before revert to ensure we are reverting to
# positives. Need to switch before revert to ensure we are reverting to
# correct repo.
# correct repo.
@ -217,7 +239,8 @@ def main():
module . exit_json ( changed = check , before = before , after = after )
module . exit_json ( changed = check , before = before , after = after )
before = svn . get_revision ( )
before = svn . get_revision ( )
local_mods = svn . has_local_mods ( )
local_mods = svn . has_local_mods ( )
svn . switch ( )
if switch :
svn . switch ( )
if local_mods :
if local_mods :
if force :
if force :
svn . revert ( )
svn . revert ( )