[style] Fix --git-index option for check-webkit-style command
authorBasuke.Suzuki@sony.com <Basuke.Suzuki@sony.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 22 Jun 2018 20:50:44 +0000 (20:50 +0000)
committerBasuke.Suzuki@sony.com <Basuke.Suzuki@sony.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 22 Jun 2018 20:50:44 +0000 (20:50 +0000)
https://bugs.webkit.org/show_bug.cgi?id=186810

When --git-index is specified, it should be compared with HEAD, not the origin/master.

Reviewed by Daniel Bates.

* Scripts/webkitpy/common/checkout/scm/git.py:
(Git.create_patch):
* Scripts/webkitpy/common/checkout/scm/scm_unittest.py:
(test_create_patch_with_git_index): Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@233097 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/Scripts/webkitpy/common/checkout/scm/git.py
Tools/Scripts/webkitpy/common/checkout/scm/scm_unittest.py

index fcd3cc7..4768bb7 100644 (file)
@@ -1,3 +1,17 @@
+2018-06-22  Basuke Suzuki  <Basuke.Suzuki@sony.com>
+
+        [style] Fix --git-index option for check-webkit-style command
+        https://bugs.webkit.org/show_bug.cgi?id=186810
+
+        When --git-index is specified, it should be compared with HEAD, not the origin/master.
+
+        Reviewed by Daniel Bates.
+
+        * Scripts/webkitpy/common/checkout/scm/git.py:
+        (Git.create_patch):
+        * Scripts/webkitpy/common/checkout/scm/scm_unittest.py:
+        (test_create_patch_with_git_index): Added.
+
 2018-06-22  Ryan Haddad  <ryanhaddad@apple.com>
 
         Unreviewed, fix syntax error introduced by r233088.
index eac451f..bc03f87 100644 (file)
@@ -336,21 +336,24 @@ class Git(SCM, SVNRepository):
 
     def create_patch(self, git_commit=None, changed_files=None, git_index=False):
         """Returns a byte array (str()) representing the patch file.
-        Patch files are effectively binary since they may contain
-        files of multiple different encodings."""
+        Patch files are effectively binary since they may contain files of multiple different encodings.
+        If git_index is True, git_commit is ignored because only indexed files are handled.
+        """
 
         # Put code changes at the top of the patch and layout tests
         # at the bottom, this makes for easier reviewing.
         config_path = self._filesystem.dirname(self._filesystem.path_to_module('webkitpy.common.config'))
         order_file = self._filesystem.join(config_path, 'orderfile')
-        order = ""
+        order = ''
         if self._filesystem.exists(order_file):
-            order = "-O%s" % order_file
+            order = '-O' + order_file
 
-        command = [self.executable_name, 'diff', '--binary', '--no-color', "--no-ext-diff", "--full-index", "--no-renames", order, self.merge_base(git_commit)]
+        command = [self.executable_name, 'diff', '--binary', '--no-color', '--no-ext-diff', '--full-index', '--no-renames', order]
         if git_index:
             command += ['--cached']
-        command += ["--"]
+        else:
+            command += [self.merge_base(git_commit)]
+        command += ['--']
         if changed_files:
             command += changed_files
         return self.prepend_svn_revision(self.run(command, decode_output=False, cwd=self.checkout_root))
index ec189b5..d73039c 100644 (file)
@@ -1021,6 +1021,26 @@ class GitTest(SCMTest):
         patch = scm.create_patch()
         self.assertNotRegexpMatches(patch, r'Subversion Revision:')
 
+    def test_create_patch_with_git_index(self):
+        # First change. Committed.
+        write_into_file_at_path('test_file_commit1', 'first cat')
+        run_command(['git', 'add', 'test_file_commit1'])
+        scm = self.tracking_scm
+        scm.commit_locally_with_message('message')
+
+        # Second change. Staged but not committed.
+        write_into_file_at_path('test_file_commit1', 'second dog')
+        run_command(['git', 'add', 'test_file_commit1'])
+
+        # Third change. Not even staged.
+        write_into_file_at_path('test_file_commit1', 'third unicorn')
+
+        patch = scm.create_patch(None, None, True)
+        self.assertRegexpMatches(patch, r'-first cat')
+        self.assertRegexpMatches(patch, r'\+second dog')
+        self.assertNotRegexpMatches(patch, r'third')
+        self.assertNotRegexpMatches(patch, r'unicorn')
+
     def test_orderfile(self):
         os.mkdir("Tools")
         os.mkdir("Source")