| OLD | NEW |
| 1 # Copyright (C) 2009 Google Inc. All rights reserved. | 1 # Copyright (C) 2009 Google Inc. All rights reserved. |
| 2 # Copyright (C) 2009 Apple Inc. All rights reserved. | 2 # Copyright (C) 2009 Apple Inc. All rights reserved. |
| 3 # Copyright (C) 2011 Daniel Bates (dbates@intudata.com). All rights reserved. | 3 # Copyright (C) 2011 Daniel Bates (dbates@intudata.com). All rights reserved. |
| 4 # | 4 # |
| 5 # Redistribution and use in source and binary forms, with or without | 5 # Redistribution and use in source and binary forms, with or without |
| 6 # modification, are permitted provided that the following conditions are | 6 # modification, are permitted provided that the following conditions are |
| 7 # met: | 7 # met: |
| 8 # | 8 # |
| 9 # * Redistributions of source code must retain the above copyright | 9 # * Redistributions of source code must retain the above copyright |
| 10 # notice, this list of conditions and the following disclaimer. | 10 # notice, this list of conditions and the following disclaimer. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 from webkitpy.common.system.executive import Executive, ScriptError | 36 from webkitpy.common.system.executive import Executive, ScriptError |
| 37 from webkitpy.common.system.executive_mock import MockExecutive | 37 from webkitpy.common.system.executive_mock import MockExecutive |
| 38 from webkitpy.common.system.filesystem import FileSystem | 38 from webkitpy.common.system.filesystem import FileSystem |
| 39 from webkitpy.common.system.filesystem_mock import MockFileSystem | 39 from webkitpy.common.system.filesystem_mock import MockFileSystem |
| 40 from webkitpy.common.checkout.scm.detection import detect_scm_system | 40 from webkitpy.common.checkout.scm.detection import detect_scm_system |
| 41 from webkitpy.common.checkout.scm.git import Git, AmbiguousCommitError | 41 from webkitpy.common.checkout.scm.git import Git, AmbiguousCommitError |
| 42 from webkitpy.common.checkout.scm.scm import SCM | 42 from webkitpy.common.checkout.scm.scm import SCM |
| 43 | 43 |
| 44 | 44 |
| 45 class SCMTestBase(unittest.TestCase): | 45 class SCMTestBase(unittest.TestCase): |
| 46 |
| 46 def __init__(self, *args, **kwargs): | 47 def __init__(self, *args, **kwargs): |
| 47 super(SCMTestBase, self).__init__(*args, **kwargs) | 48 super(SCMTestBase, self).__init__(*args, **kwargs) |
| 48 self.scm = None | 49 self.scm = None |
| 49 self.executive = None | 50 self.executive = None |
| 50 self.fs = None | 51 self.fs = None |
| 51 self.original_cwd = None | 52 self.original_cwd = None |
| 52 | 53 |
| 53 def setUp(self): | 54 def setUp(self): |
| 54 self.executive = Executive() | 55 self.executive = Executive() |
| 55 self.fs = FileSystem() | 56 self.fs = FileSystem() |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 self._mkdir("added_dir") | 145 self._mkdir("added_dir") |
| 145 self._write_text_file('added_dir/added_file', 'new stuff') | 146 self._write_text_file('added_dir/added_file', 'new stuff') |
| 146 self._write_text_file('added_dir/another_added_file', 'more new stuff') | 147 self._write_text_file('added_dir/another_added_file', 'more new stuff') |
| 147 self.scm.add('added_dir') | 148 self.scm.add('added_dir') |
| 148 self.scm.move('added_dir', 'moved_dir') | 149 self.scm.move('added_dir', 'moved_dir') |
| 149 self.assertIn('moved_dir/added_file', self.scm._added_files()) | 150 self.assertIn('moved_dir/added_file', self.scm._added_files()) |
| 150 self.assertIn('moved_dir/another_added_file', self.scm._added_files()) | 151 self.assertIn('moved_dir/another_added_file', self.scm._added_files()) |
| 151 | 152 |
| 152 | 153 |
| 153 class GitTest(SCMTestBase): | 154 class GitTest(SCMTestBase): |
| 155 |
| 154 def setUp(self): | 156 def setUp(self): |
| 155 super(GitTest, self).setUp() | 157 super(GitTest, self).setUp() |
| 156 self._set_up_git_checkouts() | 158 self._set_up_git_checkouts() |
| 157 | 159 |
| 158 def tearDown(self): | 160 def tearDown(self): |
| 159 super(GitTest, self).tearDown() | 161 super(GitTest, self).tearDown() |
| 160 self._tear_down_git_checkouts() | 162 self._tear_down_git_checkouts() |
| 161 | 163 |
| 162 def _set_up_git_checkouts(self): | 164 def _set_up_git_checkouts(self): |
| 163 """Sets up fresh git repository with one commit. Then sets up a second g
it repo that tracks the first one.""" | 165 """Sets up fresh git repository with one commit. Then sets up a second g
it repo that tracks the first one.""" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 | 219 |
| 218 Cr-Commit-Position: refs/heads/master@{#1234567} | 220 Cr-Commit-Position: refs/heads/master@{#1234567} |
| 219 """ | 221 """ |
| 220 scm = self.tracking_scm | 222 scm = self.tracking_scm |
| 221 self.assertEqual(scm._commit_position_from_git_log(git_log), 1234567) | 223 self.assertEqual(scm._commit_position_from_git_log(git_log), 1234567) |
| 222 | 224 |
| 223 def test_timestamp_of_revision(self): | 225 def test_timestamp_of_revision(self): |
| 224 scm = self.tracking_scm | 226 scm = self.tracking_scm |
| 225 scm.most_recent_log_matching(scm._commit_position_regex_for_timestamp(),
scm.checkout_root) | 227 scm.most_recent_log_matching(scm._commit_position_regex_for_timestamp(),
scm.checkout_root) |
| 226 | 228 |
| 229 |
| 227 class GitTestWithMock(SCMTestBase): | 230 class GitTestWithMock(SCMTestBase): |
| 231 |
| 228 def make_scm(self): | 232 def make_scm(self): |
| 229 scm = Git(cwd=".", executive=MockExecutive(), filesystem=MockFileSystem(
)) | 233 scm = Git(cwd=".", executive=MockExecutive(), filesystem=MockFileSystem(
)) |
| 230 scm.read_git_config = lambda *args, **kw: "MOCKKEY:MOCKVALUE" | 234 scm.read_git_config = lambda *args, **kw: "MOCKKEY:MOCKVALUE" |
| 231 return scm | 235 return scm |
| 232 | 236 |
| 233 def test_timestamp_of_revision(self): | 237 def test_timestamp_of_revision(self): |
| 234 scm = self.make_scm() | 238 scm = self.make_scm() |
| 235 scm.find_checkout_root = lambda path: '' | 239 scm.find_checkout_root = lambda path: '' |
| 236 scm._run_git = lambda args: 'Date: 2013-02-08 08:05:49 +0000' | 240 scm._run_git = lambda args: 'Date: 2013-02-08 08:05:49 +0000' |
| 237 self.assertEqual(scm.timestamp_of_revision('some-path', '12345'), '2013-
02-08T08:05:49Z') | 241 self.assertEqual(scm.timestamp_of_revision('some-path', '12345'), '2013-
02-08T08:05:49Z') |
| 238 | 242 |
| 239 scm._run_git = lambda args: 'Date: 2013-02-08 01:02:03 +0130' | 243 scm._run_git = lambda args: 'Date: 2013-02-08 01:02:03 +0130' |
| 240 self.assertEqual(scm.timestamp_of_revision('some-path', '12345'), '2013-
02-07T23:32:03Z') | 244 self.assertEqual(scm.timestamp_of_revision('some-path', '12345'), '2013-
02-07T23:32:03Z') |
| 241 | 245 |
| 242 scm._run_git = lambda args: 'Date: 2013-02-08 01:55:21 -0800' | 246 scm._run_git = lambda args: 'Date: 2013-02-08 01:55:21 -0800' |
| 243 self.assertEqual(scm.timestamp_of_revision('some-path', '12345'), '2013-
02-08T09:55:21Z') | 247 self.assertEqual(scm.timestamp_of_revision('some-path', '12345'), '2013-
02-08T09:55:21Z') |
| OLD | NEW |