Changeset 48027 in webkit


Ignore:
Timestamp:
Sep 3, 2009 12:07:21 PM (15 years ago)
Author:
ddkilzer@apple.com
Message:

<http://webkit.org/b/28880> svn-apply --force doesn't actually work

Reviewed by Eric Seidel.

This fixes "svn-apply --force" and adds unit tests for the
scm.apply_patch() method which uses this script.

  • Scripts/svn-apply: Created $globalExitCode variable that defaults to 0. Exit with a value of $globalExitCode when the script is finished. (applyPatch): Ignore a non-zero $exitCode if $force is true, but set $globalExitCode to $exitCode so that svn-apply exits with a non-zero status if any patches did not apply cleanly. Also print out the actual patch command if $force was not true.
  • Scripts/modules/scm.py: (scripts_directory): Added. Extracted from script_path(). (script_path): Extracted scripts_directory().
  • Scripts/modules/scm_unittest.py: Import urllib. (SVNTestRepository.setup): Save the original working directory in test_object since this represents the WebKit repository from where the unit tests are run. (SCMTest): Created new super class to hold utility methods. (SCMTest._create_patch): Creates a patch file on disk and a dictionary for use with scm.svn_apply(). (SCMTest._setup_webkittools_scripts_symlink): Sets up a symlink back to WebKitTools/Scripts in the test repository so that scm.apply_patch() is able to find the svn-apply script. (SVNTest): Inherit from SCMTest instead of unittest.TestCase. (SVNTest.tearDown): Make sure to change directories back to the original_path before the next test. (SVNTest.test_apply_svn_patch): New test case for applying an svn patch with scm.apply_patch(). (SVNTest.test_apply_svn_patch_force): New test case for applying an svn patch with scm.apply_patch() that conflicts. (GitTest): Inherit from SCMTest instead of unittest.TestCase. (GitTest.tearDown): Make sure to change directories back to the original_path before the next test. (GitTest.test_apply_git_patch): New test case for applying a git patch with scm.apply_patch(). (GitTest.test_apply_git_patch_force): New test case for applying a git patch with scm.apply_patch() that conflicts.
Location:
trunk/WebKitTools
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKitTools/ChangeLog

    r48009 r48027  
     12009-09-02  David Kilzer  <ddkilzer@apple.com>
     2
     3        <http://webkit.org/b/28880> svn-apply --force doesn't actually work
     4
     5        Reviewed by Eric Seidel.
     6
     7        This fixes "svn-apply --force" and adds unit tests for the
     8        scm.apply_patch() method which uses this script.
     9
     10        * Scripts/svn-apply: Created $globalExitCode variable that
     11        defaults to 0.  Exit with a value of $globalExitCode when the
     12        script is finished.
     13        (applyPatch): Ignore a non-zero $exitCode if $force is true, but
     14        set $globalExitCode to $exitCode so that svn-apply exits with a
     15        non-zero status if any patches did not apply cleanly.  Also
     16        print out the actual patch command if $force was not true.
     17
     18        * Scripts/modules/scm.py:
     19        (scripts_directory): Added.  Extracted from script_path().
     20        (script_path): Extracted scripts_directory().
     21        * Scripts/modules/scm_unittest.py: Import urllib.
     22        (SVNTestRepository.setup): Save the original working directory
     23        in test_object since this represents the WebKit repository from
     24        where the unit tests are run.
     25        (SCMTest): Created new super class to hold utility methods.
     26        (SCMTest._create_patch): Creates a patch file on disk and a
     27        dictionary for use with scm.svn_apply().
     28        (SCMTest._setup_webkittools_scripts_symlink): Sets up a symlink
     29        back to WebKitTools/Scripts in the test repository so that
     30        scm.apply_patch() is able to find the svn-apply script.
     31        (SVNTest): Inherit from SCMTest instead of unittest.TestCase.
     32        (SVNTest.tearDown): Make sure to change directories back to the
     33        original_path before the next test.
     34        (SVNTest.test_apply_svn_patch): New test case for applying an
     35        svn patch with scm.apply_patch().
     36        (SVNTest.test_apply_svn_patch_force): New test case for applying
     37        an svn patch with scm.apply_patch() that conflicts.
     38        (GitTest): Inherit from SCMTest instead of unittest.TestCase.
     39        (GitTest.tearDown): Make sure to change directories back to the
     40        original_path before the next test.
     41        (GitTest.test_apply_git_patch): New test case for applying a git
     42        patch with scm.apply_patch().
     43        (GitTest.test_apply_git_patch_force): New test case for applying
     44        a git patch with scm.apply_patch() that conflicts.
     45
    1462009-09-02  Tor Arne Vestbø  <tor.arne.vestbo@nokia.com>
    247
  • trunk/WebKitTools/Scripts/modules/scm.py

    r47953 r48027  
    100100        return output
    101101
     102    def scripts_directory(self):
     103        return os.path.join(self.checkout_root, "WebKitTools", "Scripts")
     104
    102105    def script_path(self, script_name):
    103         return os.path.join(self.checkout_root, "WebKitTools", "Scripts", script_name)
     106        return os.path.join(self.scripts_directory(), script_name)
    104107
    105108    def ensure_clean_working_directory(self, force):
  • trunk/WebKitTools/Scripts/modules/scm_unittest.py

    r47953 r48027  
    11# Copyright (C) 2009 Google Inc. All rights reserved.
     2# Copyright (C) 2009 Apple Inc. All rights reserved.
    23#
    34# Redistribution and use in source and binary forms, with or without
     
    3233import tempfile
    3334import unittest
     35import urllib
    3436from modules.scm import detect_scm_system, SCM, ScriptError
    3537
     
    8385    @classmethod
    8486    def setup(cls, test_object):
     87        test_object.original_path = os.path.abspath('.')
     88
    8589        # Create an test SVN repository
    8690        test_object.svn_repo_path = tempfile.mkdtemp(suffix="svn_test_repo")
     
    102106
    103107
    104 class SVNTest(unittest.TestCase):
     108class SCMTest(unittest.TestCase):
     109    def _create_patch(self, patch_contents):
     110        patch_path = os.path.join(self.svn_checkout_path, 'patch.diff')
     111        write_into_file_at_path(patch_path, patch_contents)
     112        patch = {}
     113        patch['reviewer'] = 'Joe Cool'
     114        patch['bug_id'] = '12345'
     115        patch['url'] = 'file://%s' % urllib.pathname2url(patch_path)
     116        return patch
     117
     118    def _setup_webkittools_scripts_symlink(self, local_scm):
     119        webkit_scm = detect_scm_system(self.original_path)
     120        webkit_scripts_directory = webkit_scm.scripts_directory()
     121        local_scripts_directory = local_scm.scripts_directory()
     122        os.mkdir(os.path.dirname(local_scripts_directory))
     123        os.symlink(webkit_scripts_directory, local_scripts_directory)
     124
     125
     126class SVNTest(SCMTest):
    105127
    106128    def setUp(self):
     
    110132    def tearDown(self):
    111133        SVNTestRepository.tear_down(self)
     134        os.chdir(self.original_path)
    112135
    113136    def test_create_patch_is_full_patch(self):
     
    138161        self.assertEqual(scm.supports_local_commits(), False)
    139162
    140 class GitTest(unittest.TestCase):
     163    def test_apply_svn_patch(self):
     164        scm = detect_scm_system(self.svn_checkout_path)
     165        patch = self._create_patch(run(['svn', 'diff', '-r4:3']))
     166        self._setup_webkittools_scripts_symlink(scm)
     167        scm.apply_patch(patch)
     168
     169    def test_apply_svn_patch_force(self):
     170        scm = detect_scm_system(self.svn_checkout_path)
     171        patch = self._create_patch(run(['svn', 'diff', '-r2:4']))
     172        self._setup_webkittools_scripts_symlink(scm)
     173        self.assertRaises(ScriptError, scm.apply_patch, patch, force=True)
     174
     175class GitTest(SCMTest):
    141176
    142177    def _setup_git_clone_of_svn_repository(self):
     
    156191        SVNTestRepository.tear_down(self)
    157192        self._tear_down_git_clone_of_svn_repository()
     193        os.chdir(self.original_path)
    158194
    159195    def test_detection(self):
     
    205241        self.assertEqual(actual_commits, expected_commits)
    206242
     243    def test_apply_git_patch(self):
     244        scm = detect_scm_system(self.git_checkout_path)
     245        patch = self._create_patch(run(['git', 'diff', 'HEAD..HEAD^']))
     246        self._setup_webkittools_scripts_symlink(scm)
     247        scm.apply_patch(patch)
     248
     249    def test_apply_git_patch_force(self):
     250        scm = detect_scm_system(self.git_checkout_path)
     251        patch = self._create_patch(run(['git', 'diff', 'HEAD~2..HEAD']))
     252        self._setup_webkittools_scripts_symlink(scm)
     253        self.assertRaises(ScriptError, scm.apply_patch, patch, force=True)
     254
    207255
    208256if __name__ == '__main__':
  • trunk/WebKitTools/Scripts/svn-apply

    r47945 r48027  
    122122);
    123123
     124my $globalExitCode = 0;
     125
    124126my $pathScriptWasRunFrom = Cwd::getcwd();
    125127my $pathForRepositoryRoot = determineVCSRoot();
     
    196198removeDirectoriesIfNeeded();
    197199
    198 exit 0;
     200exit $globalExitCode;
    199201
    200202sub addDirectoriesIfNeeded($)
     
    240242
    241243    my $exitCode = $? >> 8;
    242     if ($exitCode != 0) {
    243         print "patch -p0 \"$fullPath\" returned $exitCode.  Pass --force to ignore patch failures.\n";
    244         exit($exitCode);
     244    if ($exitCode) {
     245        if (!$force) {
     246            print "$command \"$fullPath\" returned $exitCode.  Pass --force to ignore patch failures.\n";
     247            exit $exitCode;
     248        }
     249        $globalExitCode = $exitCode;
    245250    }
    246251}
Note: See TracChangeset for help on using the changeset viewer.