def test_get_remove_files(self): test_file_path = os.path.join(self.repo_working_directory, 'r.txt') with open(test_file_path, 'w') as test_file: test_file.write('r') run_shell_command('cvs add r.txt', cwd=self.repo_working_directory, env=self.env) run_shell_command( 'cvs commit -m "{commit}"'.format(commit=self.generate_logmsg()), cwd=self.repo_working_directory, env=self.env) os.remove(test_file_path) run_shell_command('cvs remove r.txt', cwd=self.repo_working_directory, env=self.env) run_shell_command( 'cvs commit -m "{commit}"'.format(commit=self.generate_logmsg()), cwd=self.repo_working_directory, env=self.env) sut = cvs.open_repository(self.repo_working_directory) version = sut.get_head_version('r.txt') major, minor = version.split('.') previous_version = "{major}.{minor}".format(major=major, minor=(int(minor) - 1)) changes = sut.get_changeset().changes self.assertEqual(changes, [ change.Change(sut, "r.txt", previous_version, "r.txt", version, change.ChangeType.remove) ])
def test_get_modify_files(self): test_file_path = os.path.join(self.repo_working_directory, 'm.txt') with open(test_file_path, 'w') as test_file: test_file.write('a') run_shell_command('cvs add m.txt', cwd=self.repo_working_directory, env=self.env) run_shell_command( 'cvs commit -m "{commit}"'.format(commit=self.generate_logmsg()), cwd=self.repo_working_directory, env=self.env) time.sleep(1) # CVS commits aren't synchronous with open(test_file_path, 'a') as test_file: test_file.write('\nb\n') run_shell_command( 'cvs commit -m "{commit}"'.format(commit=self.generate_logmsg()), cwd=self.repo_working_directory, env=self.env) sut = cvs.open_repository(self.repo_working_directory) version = sut.get_head_version('m.txt') major, minor = version.split('.') previous_version = "{major}.{minor}".format(major=major, minor=(int(minor) - 1)) changes = sut.get_changeset().changes self.assertEqual(changes, [ change.Change(sut, "m.txt", previous_version, "m.txt", version, change.ChangeType.modify) ])
def test_get_modified_file(self): sut = git.open_repository(self.repository_path) file_path = os.path.join(self.repository_path, 'test.txt') with open(file_path, 'w') as out_file: out_file.write("a") command = 'git add test.txt' subprocess.run(shlex.split(command), cwd=self.repository_path, env=self.test_env) command = 'git commit -m "Added file"' subprocess.run(shlex.split(command), cwd=self.repository_path, env=self.test_env) revision_a = sut.client.commit().binsha with open(file_path, 'w') as out_file: out_file.write("b") command = 'git add test.txt' subprocess.run(shlex.split(command), cwd=self.repository_path, env=self.test_env) command = 'git commit -m "Updated file"' subprocess.run(shlex.split(command), cwd=self.repository_path, env=self.test_env) revision_b = sut.client.commit().binsha changeset = sut.get_changeset() self.assertEqual(changeset.changes, [ change.Change(sut, "test.txt", revision_a, "test.txt", revision_b, change.ChangeType.modify) ])
def test_get_removed_file(self): sut = git.open_repository(self.repository_path) file_path = os.path.join(self.repository_path, 'test.txt') with open(file_path, 'w') as out_file: out_file.write("a") command = 'git add test.txt' subprocess.run(shlex.split(command), cwd=self.repository_path, env=self.test_env) command = 'git commit -m "Test Remove file - initial add"' subprocess.run(shlex.split(command), cwd=self.repository_path, env=self.test_env) revision = sut.client.commit().binsha command = 'git rm -f test.txt' subprocess.run(shlex.split(command), cwd=self.repository_path, env=self.test_env) command = 'git commit -m "Test Remove file - remove file"' subprocess.run(shlex.split(command), cwd=self.repository_path, env=self.test_env) changeset = sut.get_changeset() self.assertEqual(changeset.changes, [ change.Change(sut, "test.txt", revision, None, None, change.ChangeType.remove) ])
def test_get_add_files(self): test_file = os.path.join(self.repo_working_directory, 'a.txt') with open(test_file, 'w') as test_file: test_file.write('a') run_shell_command('svn add a.txt', cwd=self.repo_working_directory) run_shell_command('svn commit -m "Test"', cwd=self.repo_working_directory) run_shell_command('svn up', cwd=self.repo_working_directory) sut = svn.SVNRepository(self.repo_working_directory) revision = sut.info()['commit']['@revision'] changes = sut.get_changeset(revision).changes self.assertEqual(changes, [ change.Change(sut, None, None, "a.txt", revision, change.ChangeType.add) ])
def test_get_add_files(self): test_file_path = os.path.join(self.repo_working_directory, 'a.txt') with open(test_file_path, 'w') as test_file: test_file.write('a') run_shell_command('cvs add a.txt', cwd=self.repo_working_directory, env=self.env) run_shell_command( 'cvs commit -m "{commit}"'.format(commit=self.generate_logmsg()), cwd=self.repo_working_directory, env=self.env) sut = cvs.open_repository(self.repo_working_directory) version = sut.get_head_version('a.txt') changes = sut.get_changeset().changes self.assertEqual(changes, [ change.Change(sut, None, None, "a.txt", version, change.ChangeType.add) ])
def test_get_derived_file(self): sut = git.open_repository(self.repository_path) old_file_path = os.path.join(self.repository_path, 'test_old.txt') new_file_path = os.path.join(self.repository_path, 'test.txt') with open(old_file_path, 'w') as out_file: out_file.write("abcdefghijklmnopqrstuvwxyz\n" * 100) command = 'git add test_old.txt' subprocess.run(shlex.split(command), cwd=self.repository_path, env=self.test_env) command = 'git commit -m "Test Derive: Added file"' subprocess.run(shlex.split(command), cwd=self.repository_path, env=self.test_env) revision_a = sut.client.commit().binsha with open(new_file_path, 'w') as out_file: out_file.write("abcdefghijklmnopqrstuvwxyz\n" * 110) command = 'git rm -r test_old.txt' subprocess.run(shlex.split(command), cwd=self.repository_path, env=self.test_env) command = 'git add test.txt' subprocess.run(shlex.split(command), cwd=self.repository_path, env=self.test_env) command = 'git commit -m "Test Derive: Updated file"' subprocess.run(shlex.split(command), cwd=self.repository_path, env=self.test_env) revision_b = sut.client.commit().binsha print(sut.client.commit().message) changeset = sut.get_changeset() self.assertEqual(changeset.changes, [ change.Change(sut, "test_old.txt", revision_a, "test.txt", revision_b, change.ChangeType.derived) ])
def test_get_changeset(self): sut = hg.open_repository(self.repository_path) changeset = sut.get_changeset('0') self.assertEqual(changeset.changes, [ change.Change(sut, None, None, "a.txt", '0', change.ChangeType.add) ])