def scm(self): # Lazily initialize SCM to not error-out before command line parsing (or when running non-scm commands). original_cwd = os.path.abspath(".") if not self._scm: self._scm = detect_scm_system(original_cwd) if not self._scm: script_directory = os.path.abspath(sys.path[0]) self._scm = detect_scm_system(script_directory) if self._scm: log("The current directory (%s) is not a WebKit checkout, using %s" % (original_cwd, self._scm.checkout_root)) else: error("FATAL: Failed to determine the SCM system for either %s or %s" % (original_cwd, script_directory)) return self._scm
def test_create_binary_patch(self): # Create a git binary patch and check the contents. scm = detect_scm_system(self.git_checkout_path) test_file_name = 'binary_file' test_file_path = os.path.join(self.git_checkout_path, test_file_name) file_contents = ''.join(map(chr, range(256))) write_into_file_at_path(test_file_path, file_contents) run_command(['git', 'add', test_file_name]) patch = scm.create_patch() self.assertTrue(re.search(r'\nliteral 0\n', patch)) self.assertTrue(re.search(r'\nliteral 256\n', patch)) # Check if we can apply the created patch. run_command(['git', 'rm', '-f', test_file_name]) self._setup_webkittools_scripts_symlink(scm) self.scm.apply_patch(self._create_patch(patch)) self.assertEqual(file_contents, read_from_path(test_file_path)) # Check if we can create a patch from a local commit. write_into_file_at_path(test_file_path, file_contents) run_command(['git', 'add', test_file_name]) run_command(['git', 'commit', '-m', 'binary diff']) patch_from_local_commit = scm.create_patch_from_local_commit('HEAD') self.assertTrue(re.search(r'\nliteral 0\n', patch_from_local_commit)) self.assertTrue(re.search(r'\nliteral 256\n', patch_from_local_commit)) patch_since_local_commit = scm.create_patch_since_local_commit('HEAD^1') self.assertTrue(re.search(r'\nliteral 0\n', patch_since_local_commit)) self.assertTrue(re.search(r'\nliteral 256\n', patch_since_local_commit)) self.assertEqual(patch_from_local_commit, patch_since_local_commit)
def test_rebase_in_progress(self): svn_test_file = os.path.join(self.svn_checkout_path, 'test_file') write_into_file_at_path(svn_test_file, "svn_checkout") run_command([ 'svn', 'commit', '--message', 'commit to conflict with git commit' ], cwd=self.svn_checkout_path) git_test_file = os.path.join(self.git_checkout_path, 'test_file') write_into_file_at_path(git_test_file, "git_checkout") run_command([ 'git', 'commit', '-a', '-m', 'commit to be thrown away by rebase abort' ]) # --quiet doesn't make git svn silent, so use run_silent to redirect output self.assertRaises( ScriptError, run_silent, ['git', 'svn', '--quiet', 'rebase' ]) # Will fail due to a conflict leaving us mid-rebase. scm = detect_scm_system(self.git_checkout_path) self.assertTrue(scm.rebase_in_progress()) # Make sure our cleanup works. scm.clean_working_directory() self.assertFalse(scm.rebase_in_progress()) # Make sure cleanup doesn't throw when no rebase is in progress. scm.clean_working_directory()
def tear_down(cls, test_object): run_command(['rm', '-rf', test_object.svn_repo_path]) run_command(['rm', '-rf', test_object.svn_checkout_path]) # Now that we've deleted the checkout paths, cwddir may be invalid # Change back to a valid directory so that later calls to os.getcwd() do not fail. os.chdir(detect_scm_system(os.path.dirname(__file__)).checkout_root)
def test_create_patch_is_full_patch(self): test_dir_path = os.path.join(self.svn_checkout_path, 'test_dir') os.mkdir(test_dir_path) test_file_path = os.path.join(test_dir_path, 'test_file2') write_into_file_at_path(test_file_path, 'test content') run_command(['svn', 'add', 'test_dir']) # create_patch depends on 'svn-create-patch', so make a dummy version. scripts_path = os.path.join(self.svn_checkout_path, 'WebKitTools', 'Scripts') os.makedirs(scripts_path) create_patch_path = os.path.join(scripts_path, 'svn-create-patch') write_into_file_at_path( create_patch_path, '#!/bin/sh\necho $PWD' ) # We could pass -n to prevent the \n, but not all echo accept -n. os.chmod(create_patch_path, stat.S_IXUSR | stat.S_IRUSR) # Change into our test directory and run the create_patch command. os.chdir(test_dir_path) scm = detect_scm_system(test_dir_path) self.assertEqual(scm.checkout_root, self.svn_checkout_path ) # Sanity check that detection worked right. patch_contents = scm.create_patch() # Our fake 'svn-create-patch' returns $PWD instead of a patch, check that it was executed from the root of the repo. self.assertEqual("%s\n" % os.path.realpath(scm.checkout_root), patch_contents) # Add a \n because echo adds a \n.
def _setup_webkittools_scripts_symlink(self, local_scm): webkit_scm = detect_scm_system( os.path.dirname(os.path.abspath(__file__))) webkit_scripts_directory = webkit_scm.scripts_directory() local_scripts_directory = local_scm.scripts_directory() os.mkdir(os.path.dirname(local_scripts_directory)) os.symlink(webkit_scripts_directory, local_scripts_directory)
def test_not_have_authorization_for_realm(self): scm = detect_scm_system(self.svn_checkout_path) fake_home_dir = tempfile.mkdtemp(suffix="fake_home_dir") svn_config_dir_path = os.path.join(fake_home_dir, ".subversion") os.mkdir(svn_config_dir_path) self.assertFalse(scm.has_authorization_for_realm(home_directory=fake_home_dir)) os.rmdir(svn_config_dir_path) os.rmdir(fake_home_dir)
def test_commitish_parsing(self): scm = detect_scm_system(self.git_checkout_path) # Multiple revisions are cherry-picked. self.assertEqual(len(scm.commit_ids_from_commitish_arguments(['HEAD~2'])), 1) self.assertEqual(len(scm.commit_ids_from_commitish_arguments(['HEAD', 'HEAD~2'])), 2) # ... is an invalid range specifier self.assertRaises(ScriptError, scm.commit_ids_from_commitish_arguments, ['trunk...HEAD'])
def scm(self): # Lazily initialize SCM to not error-out before command line parsing (or when running non-scm commands). original_cwd = os.path.abspath(".") if not self._scm: self._scm = detect_scm_system(original_cwd) if not self._scm: script_directory = os.path.abspath(sys.path[0]) self._scm = detect_scm_system(script_directory) if self._scm: log("The current directory (%s) is not a WebKit checkout, using %s" % (original_cwd, self._scm.checkout_root)) else: error( "FATAL: Failed to determine the SCM system for either %s or %s" % (original_cwd, script_directory)) return self._scm
def test_commitish_order(self): scm = detect_scm_system(self.git_checkout_path) commit_range = 'HEAD~3..HEAD' actual_commits = scm.commit_ids_from_commitish_arguments([commit_range]) expected_commits = [] expected_commits += reversed(run_command(['git', 'rev-list', commit_range]).splitlines()) self.assertEqual(actual_commits, expected_commits)
def test_has_authorization_for_realm(self): scm = detect_scm_system(self.svn_checkout_path) fake_home_dir = tempfile.mkdtemp(suffix="fake_home_dir") svn_config_dir_path = os.path.join(fake_home_dir, ".subversion") os.mkdir(svn_config_dir_path) fake_webkit_auth_file = os.path.join(svn_config_dir_path, "fake_webkit_auth_file") write_into_file_at_path(fake_webkit_auth_file, SVN.svn_server_realm) self.assertTrue(scm.has_authorization_for_realm(home_directory=fake_home_dir)) os.remove(fake_webkit_auth_file) os.rmdir(svn_config_dir_path) os.rmdir(fake_home_dir)
def test_create_patch_is_full_patch(self): test_dir_path = os.path.join(self.svn_checkout_path, 'test_dir') os.mkdir(test_dir_path) test_file_path = os.path.join(test_dir_path, 'test_file2') write_into_file_at_path(test_file_path, 'test content') run_command(['svn', 'add', 'test_dir']) # create_patch depends on 'svn-create-patch', so make a dummy version. scripts_path = os.path.join(self.svn_checkout_path, 'WebKitTools', 'Scripts') os.makedirs(scripts_path) create_patch_path = os.path.join(scripts_path, 'svn-create-patch') write_into_file_at_path(create_patch_path, '#!/bin/sh\necho $PWD') # We could pass -n to prevent the \n, but not all echo accept -n. os.chmod(create_patch_path, stat.S_IXUSR | stat.S_IRUSR) # Change into our test directory and run the create_patch command. os.chdir(test_dir_path) scm = detect_scm_system(test_dir_path) self.assertEqual(scm.checkout_root, self.svn_checkout_path) # Sanity check that detection worked right. patch_contents = scm.create_patch() # Our fake 'svn-create-patch' returns $PWD instead of a patch, check that it was executed from the root of the repo. self.assertEqual("%s\n" % os.path.realpath(scm.checkout_root), patch_contents) # Add a \n because echo adds a \n.
def test_rebase_in_progress(self): svn_test_file = os.path.join(self.svn_checkout_path, 'test_file') write_into_file_at_path(svn_test_file, "svn_checkout") run_command(['svn', 'commit', '--message', 'commit to conflict with git commit'], cwd=self.svn_checkout_path) git_test_file = os.path.join(self.git_checkout_path, 'test_file') write_into_file_at_path(git_test_file, "git_checkout") run_command(['git', 'commit', '-a', '-m', 'commit to be thrown away by rebase abort']) # --quiet doesn't make git svn silent, so use run_silent to redirect output self.assertRaises(ScriptError, run_silent, ['git', 'svn', '--quiet', 'rebase']) # Will fail due to a conflict leaving us mid-rebase. scm = detect_scm_system(self.git_checkout_path) self.assertTrue(scm.rebase_in_progress()) # Make sure our cleanup works. scm.clean_working_directory() self.assertFalse(scm.rebase_in_progress()) # Make sure cleanup doesn't throw when no rebase is in progress. scm.clean_working_directory()
def test_detection(self): scm = detect_scm_system(self.svn_checkout_path) self.assertEqual(scm.display_name(), "svn") self.assertEqual(scm.supports_local_commits(), False)
def test_apply_git_patch_force(self): scm = detect_scm_system(self.git_checkout_path) patch = self._create_patch(run_command(['git', 'diff', 'HEAD~2..HEAD'])) self._setup_webkittools_scripts_symlink(scm) self.assertRaises(ScriptError, scm.apply_patch, patch, force=True)
def test_apply_git_patch(self): scm = detect_scm_system(self.git_checkout_path) patch = self._create_patch(run_command(['git', 'diff', 'HEAD..HEAD^'])) self._setup_webkittools_scripts_symlink(scm) scm.apply_patch(patch)
def _setup_webkittools_scripts_symlink(self, local_scm): webkit_scm = detect_scm_system(os.path.dirname(os.path.abspath(__file__))) webkit_scripts_directory = webkit_scm.scripts_directory() local_scripts_directory = local_scm.scripts_directory() os.mkdir(os.path.dirname(local_scripts_directory)) os.symlink(webkit_scripts_directory, local_scripts_directory)
def setUp(self): SVNTestRepository.setup(self) os.chdir(self.svn_checkout_path) self.scm = detect_scm_system(self.svn_checkout_path)
def test_detection(self): scm = detect_scm_system(self.git_checkout_path) self.assertEqual(scm.display_name(), "git") self.assertEqual(scm.supports_local_commits(), True)
def setUp(self): SVNTestRepository.setup(self) self._setup_git_clone_of_svn_repository() os.chdir(self.git_checkout_path) self.scm = detect_scm_system(self.git_checkout_path)
def test_apply_svn_patch(self): scm = detect_scm_system(self.svn_checkout_path) patch = self._create_patch(run_command(['svn', 'diff', '-r4:3'])) self._setup_webkittools_scripts_symlink(scm) scm.apply_patch(patch)