import os
import svntest
Skip = svntest.testcase.Skip
SkipUnless = svntest.testcase.SkipUnless
XFail = svntest.testcase.XFail
Item = svntest.wc.StateItem
def add_files(sbox):
"schedule: add some files"
sbox.build(read_only = True)
wc_dir = sbox.wc_dir
delta_path = os.path.join(wc_dir, 'delta')
zeta_path = os.path.join(wc_dir, 'A', 'B', 'zeta')
epsilon_path = os.path.join(wc_dir, 'A', 'D', 'G', 'epsilon')
svntest.main.file_append(delta_path, "This is the file 'delta'.")
svntest.main.file_append(zeta_path, "This is the file 'zeta'.")
svntest.main.file_append(epsilon_path, "This is the file 'epsilon'.")
svntest.main.run_svn(None, 'add', delta_path, zeta_path, epsilon_path)
expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
expected_status.add({
'delta' : Item(status='A ', wc_rev=0),
'A/B/zeta' : Item(status='A ', wc_rev=0),
'A/D/G/epsilon' : Item(status='A ', wc_rev=0),
})
svntest.actions.run_and_verify_status(wc_dir, expected_status)
def add_directories(sbox):
"schedule: add some directories"
sbox.build(read_only = True)
wc_dir = sbox.wc_dir
X_path = os.path.join(wc_dir, 'X')
Y_path = os.path.join(wc_dir, 'A', 'C', 'Y')
Z_path = os.path.join(wc_dir, 'A', 'D', 'H', 'Z')
os.mkdir(X_path)
os.mkdir(Y_path)
os.mkdir(Z_path)
svntest.main.run_svn(None, 'add', X_path, Y_path, Z_path)
expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
expected_status.add({
'X' : Item(status='A ', wc_rev=0),
'A/C/Y' : Item(status='A ', wc_rev=0),
'A/D/H/Z' : Item(status='A ', wc_rev=0),
})
svntest.actions.run_and_verify_status(wc_dir, expected_status)
def nested_adds(sbox):
"schedule: add some nested files and directories"
sbox.build(read_only = True)
wc_dir = sbox.wc_dir
X_path = os.path.join(wc_dir, 'X')
Y_path = os.path.join(wc_dir, 'A', 'C', 'Y')
Z_path = os.path.join(wc_dir, 'A', 'D', 'H', 'Z')
os.mkdir(X_path)
os.mkdir(Y_path)
os.mkdir(Z_path)
P_path = os.path.join(X_path, 'P')
Q_path = os.path.join(Y_path, 'Q')
R_path = os.path.join(Z_path, 'R')
os.mkdir(P_path)
os.mkdir(Q_path)
os.mkdir(R_path)
delta_path = os.path.join(X_path, 'delta')
epsilon_path = os.path.join(Y_path, 'epsilon')
upsilon_path = os.path.join(Y_path, 'upsilon')
zeta_path = os.path.join(Z_path, 'zeta')
svntest.main.file_append(delta_path, "This is the file 'delta'.")
svntest.main.file_append(epsilon_path, "This is the file 'epsilon'.")
svntest.main.file_append(upsilon_path, "This is the file 'upsilon'.")
svntest.main.file_append(zeta_path, "This is the file 'zeta'.")
svntest.main.run_svn(None, 'add', X_path, Y_path, Z_path)
expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
expected_status.add({
'X' : Item(status='A ', wc_rev=0),
'A/C/Y' : Item(status='A ', wc_rev=0),
'A/D/H/Z' : Item(status='A ', wc_rev=0),
'X/P' : Item(status='A ', wc_rev=0),
'A/C/Y/Q' : Item(status='A ', wc_rev=0),
'A/D/H/Z/R' : Item(status='A ', wc_rev=0),
'X/delta' : Item(status='A ', wc_rev=0),
'A/C/Y/epsilon' : Item(status='A ', wc_rev=0),
'A/C/Y/upsilon' : Item(status='A ', wc_rev=0),
'A/D/H/Z/zeta' : Item(status='A ', wc_rev=0),
})
svntest.actions.run_and_verify_status(wc_dir, expected_status)
def add_executable(sbox):
"schedule: add some executable files"
sbox.build(read_only = True)
def runTest(wc_dir, fileName, perm, executable):
fileName = os.path.join(wc_dir, fileName)
if executable:
expected_out = ["*\n"]
else:
expected_out = []
f = open(fileName,"w")
f.close()
os.chmod(fileName,perm)
svntest.main.run_svn(None, 'add', fileName)
svntest.actions.run_and_verify_svn(None, expected_out, [],
'propget', "svn:executable", fileName)
test_cases = [
("all_exe", 0777, 1),
("none_exe", 0666, 0),
("user_exe", 0766, 1),
("group_exe", 0676, 0),
("other_exe", 0667, 0),
]
for test_case in test_cases:
runTest(sbox.wc_dir, *test_case)
def delete_files(sbox):
"schedule: delete some files"
sbox.build(read_only = True)
wc_dir = sbox.wc_dir
iota_path = os.path.join(wc_dir, 'iota')
mu_path = os.path.join(wc_dir, 'A', 'mu')
rho_path = os.path.join(wc_dir, 'A', 'D', 'G', 'rho')
omega_path = os.path.join(wc_dir, 'A', 'D', 'H', 'omega')
svntest.main.run_svn(None, 'del', iota_path, mu_path, rho_path, omega_path)
expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
expected_status.tweak('iota', 'A/mu', 'A/D/G/rho', 'A/D/H/omega',
status='D ')
svntest.actions.run_and_verify_status(wc_dir, expected_status)
def delete_dirs(sbox):
"schedule: delete some directories"
sbox.build(read_only = True)
wc_dir = sbox.wc_dir
E_path = os.path.join(wc_dir, 'A', 'B', 'E')
F_path = os.path.join(wc_dir, 'A', 'B', 'F')
H_path = os.path.join(wc_dir, 'A', 'D', 'H')
alpha_path = os.path.join(E_path, 'alpha')
beta_path = os.path.join(E_path, 'beta')
chi_path = os.path.join(H_path, 'chi')
omega_path = os.path.join(H_path, 'omega')
psi_path = os.path.join(H_path, 'psi')
svntest.main.run_svn(None, 'del', E_path, F_path, H_path)
expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
expected_status.tweak('A/B/E', 'A/B/E/alpha', 'A/B/E/beta',
'A/B/F',
'A/D/H', 'A/D/H/chi', 'A/D/H/omega', 'A/D/H/psi',
status='D ')
svntest.actions.run_and_verify_status(wc_dir, expected_status)
def check_reversion(files, output):
expected_output = []
for file in files:
expected_output = expected_output + ["Reverted '" + file + "'\n"]
output.sort()
expected_output.sort()
if output != expected_output:
print("Expected output: %s" % expected_output)
print("Actual output: %s" % output)
raise svntest.Failure
def revert_add_files(sbox):
"revert: add some files"
add_files(sbox)
wc_dir = sbox.wc_dir
delta_path = os.path.join(wc_dir, 'delta')
zeta_path = os.path.join(wc_dir, 'A', 'B', 'zeta')
epsilon_path = os.path.join(wc_dir, 'A', 'D', 'G', 'epsilon')
files = [delta_path, zeta_path, epsilon_path]
exit_code, output, err = svntest.actions.run_and_verify_svn(None, None, [],
'revert',
'--recursive',
wc_dir)
check_reversion(files, output)
def revert_add_directories(sbox):
"revert: add some directories"
add_directories(sbox)
wc_dir = sbox.wc_dir
X_path = os.path.join(wc_dir, 'X')
Y_path = os.path.join(wc_dir, 'A', 'C', 'Y')
Z_path = os.path.join(wc_dir, 'A', 'D', 'H', 'Z')
files = [X_path, Y_path, Z_path]
exit_code, output, err = svntest.actions.run_and_verify_svn(None, None, [],
'revert',
'--recursive',
wc_dir)
check_reversion(files, output)
def revert_nested_adds(sbox):
"revert: add some nested files and directories"
nested_adds(sbox)
wc_dir = sbox.wc_dir
X_path = os.path.join(wc_dir, 'X')
Y_path = os.path.join(wc_dir, 'A', 'C', 'Y')
Z_path = os.path.join(wc_dir, 'A', 'D', 'H', 'Z')
files = [X_path, Y_path, Z_path]
exit_code, output, err = svntest.actions.run_and_verify_svn(None, None, [],
'revert',
'--recursive',
wc_dir)
check_reversion(files, output)
def revert_add_executable(sbox):
"revert: add some executable files"
add_executable(sbox)
wc_dir = sbox.wc_dir
all_path = os.path.join(wc_dir, 'all_exe')
none_path = os.path.join(wc_dir, 'none_exe')
user_path = os.path.join(wc_dir, 'user_exe')
group_path = os.path.join(wc_dir, 'group_exe')
other_path = os.path.join(wc_dir, 'other_exe')
files = [all_path, none_path, user_path, group_path, other_path]
exit_code, output, err = svntest.actions.run_and_verify_svn(None, None, [],
'revert',
'--recursive',
wc_dir)
check_reversion(files, output)
def revert_delete_files(sbox):
"revert: delete some files"
delete_files(sbox)
wc_dir = sbox.wc_dir
iota_path = os.path.join(wc_dir, 'iota')
mu_path = os.path.join(wc_dir, 'A', 'mu')
rho_path = os.path.join(wc_dir, 'A', 'D', 'G', 'rho')
omega_path = os.path.join(wc_dir, 'A', 'D', 'H', 'omega')
files = [iota_path, mu_path, omega_path, rho_path]
exit_code, output, err = svntest.actions.run_and_verify_svn(None, None, [],
'revert',
'--recursive',
wc_dir)
check_reversion(files, output)
def revert_delete_dirs(sbox):
"revert: delete some directories"
delete_dirs(sbox)
wc_dir = sbox.wc_dir
E_path = os.path.join(wc_dir, 'A', 'B', 'E')
F_path = os.path.join(wc_dir, 'A', 'B', 'F')
H_path = os.path.join(wc_dir, 'A', 'D', 'H')
alpha_path = os.path.join(E_path, 'alpha')
beta_path = os.path.join(E_path, 'beta')
chi_path = os.path.join(H_path, 'chi')
omega_path = os.path.join(H_path, 'omega')
psi_path = os.path.join(H_path, 'psi')
files = [E_path, F_path, H_path,
alpha_path, beta_path, chi_path, omega_path, psi_path]
exit_code, output, err = svntest.actions.run_and_verify_svn(None, None, [],
'revert',
'--recursive',
wc_dir)
check_reversion(files, output)
def unschedule_missing_added(sbox):
"unschedule addition on missing items"
sbox.build(read_only = True)
wc_dir = sbox.wc_dir
file1_path = os.path.join(wc_dir, 'file1')
file2_path = os.path.join(wc_dir, 'file2')
dir1_path = os.path.join(wc_dir, 'dir1')
dir2_path = os.path.join(wc_dir, 'dir2')
svntest.main.file_append(file1_path, "This is the file 'file1'.")
svntest.main.file_append(file2_path, "This is the file 'file2'.")
svntest.main.run_svn(None, 'add', file1_path, file2_path)
svntest.main.run_svn(None, 'mkdir', dir1_path, dir2_path)
expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
expected_status.add({
'file1' : Item(status='A ', wc_rev=0),
'file2' : Item(status='A ', wc_rev=0),
'dir1' : Item(status='A ', wc_rev=0),
'dir2' : Item(status='A ', wc_rev=0),
})
svntest.actions.run_and_verify_status(wc_dir, expected_status)
os.remove(file1_path)
os.remove(file2_path)
svntest.main.safe_rmtree(dir1_path)
svntest.main.safe_rmtree(dir2_path)
svntest.main.run_svn(svntest.verify.AnyOutput, 'rm', file1_path)
svntest.main.run_svn(svntest.verify.AnyOutput, 'rm', dir1_path)
svntest.main.run_svn(None, 'revert', file2_path, dir2_path)
expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
svntest.actions.run_and_verify_status(wc_dir, expected_status)
def delete_missing(sbox):
"schedule and commit deletion on missing items"
sbox.build()
wc_dir = sbox.wc_dir
mu_path = os.path.join(wc_dir, 'A', 'mu')
H_path = os.path.join(wc_dir, 'A', 'D', 'H')
os.remove(mu_path)
svntest.main.safe_rmtree(H_path)
svntest.actions.run_and_verify_svn(None, None, [], 'rm', mu_path, H_path)
expected_output = svntest.wc.State(wc_dir, {
'A/mu' : Item(verb='Deleting'),
'A/D/H' : Item(verb='Deleting'),
})
expected_status = svntest.actions.get_virginal_state(wc_dir, 2)
expected_status.remove('A/mu', 'A/D/H',
'A/D/H/psi', 'A/D/H/omega', 'A/D/H/chi')
expected_status.tweak(wc_rev=1)
svntest.actions.run_and_verify_commit(wc_dir,
expected_output,
expected_status,
None, wc_dir)
def revert_inside_newly_added_dir(sbox):
"revert inside a newly added dir"
sbox.build(read_only = True)
wc_dir = sbox.wc_dir
os.chdir(wc_dir)
os.mkdir('foo')
svntest.main.run_svn(None, 'add', 'foo')
os.chdir('foo')
svntest.actions.run_and_verify_svn(None, None, svntest.verify.AnyOutput,
'revert', '.')
def status_add_deleted_directory(sbox):
"status after add of deleted directory"
sbox.build()
wc_dir = sbox.wc_dir
A_path = os.path.join(wc_dir, 'A')
svntest.actions.run_and_verify_svn(None, None, [], 'rm', A_path)
svntest.main.safe_rmtree(A_path)
svntest.actions.run_and_verify_svn(None, None, [],
'ci', '-m', 'log msg', wc_dir)
svntest.actions.run_and_verify_svn(None, None, [], 'mkdir', A_path)
expected_status = svntest.actions.get_virginal_state(wc_dir, 2)
expected_status = svntest.wc.State(wc_dir,
{ '' : Item(status=' ', wc_rev=1),
'A' : Item(status='A ', wc_rev=0),
'iota' : Item(status=' ', wc_rev=1),
})
svntest.actions.run_and_verify_status(wc_dir, expected_status)
svntest.actions.run_and_verify_svn(None, ['At revision 2.\n'], [],
'up', wc_dir)
expected_status.tweak('', 'iota', wc_rev=2)
svntest.actions.run_and_verify_status(wc_dir, expected_status)
def add_recursive_already_versioned(sbox):
"'svn add' should traverse already-versioned dirs"
wc_dir = sbox.wc_dir
if svntest.actions.make_repo_and_wc(sbox):
return 1
delta_path = os.path.join(wc_dir, 'delta')
zeta_path = os.path.join(wc_dir, 'A', 'B', 'zeta')
epsilon_path = os.path.join(wc_dir, 'A', 'D', 'G', 'epsilon')
svntest.main.file_append(delta_path, "This is the file 'delta'.")
svntest.main.file_append(zeta_path, "This is the file 'zeta'.")
svntest.main.file_append(epsilon_path, "This is the file 'epsilon'.")
expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
expected_status.add({
'delta' : Item(status='A ', wc_rev=0),
'A/B/zeta' : Item(status='A ', wc_rev=0),
'A/D/G/epsilon' : Item(status='A ', wc_rev=0),
})
svntest.main.run_svn(None, 'revert', '--recursive', wc_dir)
saved_wd = os.getcwd()
os.chdir(wc_dir)
svntest.main.run_svn(None, 'add', '--force', '.')
os.chdir(saved_wd)
svntest.actions.run_and_verify_status(wc_dir, expected_status)
def fail_add_directory(sbox):
"'svn mkdir' should clean up after itself on error"
svntest.main.safe_rmtree(sbox.wc_dir)
os.makedirs(sbox.wc_dir)
os.chdir(sbox.wc_dir)
svntest.actions.run_and_verify_svn('Failed mkdir',
None, svntest.verify.AnyOutput,
'mkdir', 'A')
if os.path.exists('A'):
raise svntest.Failure('svn mkdir created an unversioned directory')
def delete_non_existent(sbox):
"'svn rm non-existent' should exit with an error"
sbox.build(read_only = True)
wc_dir = sbox.wc_dir
os.chdir(wc_dir)
svntest.actions.run_and_verify_svn(None, None, svntest.verify.AnyOutput,
'rm', '--force', 'non-existent')
test_list = [ None,
revert_add_files,
revert_add_directories,
revert_nested_adds,
SkipUnless(revert_add_executable, svntest.main.is_posix_os),
revert_delete_files,
revert_delete_dirs,
unschedule_missing_added,
delete_missing,
revert_inside_newly_added_dir,
status_add_deleted_directory,
add_recursive_already_versioned,
fail_add_directory,
delete_non_existent,
]
if __name__ == '__main__':
svntest.main.run_tests(test_list)