1# Copyright (C) 2011 Google Inc. All rights reserved.
2#
3# Redistribution and use in source and binary forms, with or without
4# modification, are permitted provided that the following conditions are
5# met:
6#
7#    * Redistributions of source code must retain the above copyright
8# notice, this list of conditions and the following disclaimer.
9#    * Redistributions in binary form must reproduce the above
10# copyright notice, this list of conditions and the following disclaimer
11# in the documentation and/or other materials provided with the
12# distribution.
13#    * Neither the name of Google Inc. nor the names of its
14# contributors may be used to endorse or promote products derived from
15# this software without specific prior written permission.
16#
17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29from webkitpy.common.system.filesystem_mock import MockFileSystem
30from webkitpy.common.system.executive_mock import MockExecutive
31
32
33class MockSCM(object):
34    executable_name = "MockSCM"
35
36    def __init__(self, filesystem=None, executive=None):
37        self.checkout_root = "/mock-checkout/third_party/WebKit"
38        self.added_paths = set()
39        self._filesystem = filesystem or MockFileSystem()
40        self._executive = executive or MockExecutive()
41
42    def add(self, destination_path, return_exit_code=False):
43        self.add_list([destination_path], return_exit_code)
44
45    def add_list(self, destination_paths, return_exit_code=False):
46        self.added_paths.update(set(destination_paths))
47        if return_exit_code:
48            return 0
49
50    def has_working_directory_changes(self):
51        return False
52
53    def ensure_cleanly_tracking_remote_master(self):
54        pass
55
56    def current_branch(self):
57        return "mock-branch-name"
58
59    def checkout_branch(self, name):
60        pass
61
62    def create_clean_branch(self, name):
63        pass
64
65    def delete_branch(self, name):
66        pass
67
68    def supports_local_commits(self):
69        return True
70
71    def exists(self, path):
72        # TestRealMain.test_real_main (and several other rebaseline tests) are sensitive to this return value.
73        # We should make those tests more robust, but for now we just return True always (since no test needs otherwise).
74        return True
75
76    def absolute_path(self, *comps):
77        return self._filesystem.join(self.checkout_root, *comps)
78
79    def svn_revision(self, path):
80        return '5678'
81
82    def svn_revision_from_git_commit(self, git_commit):
83        if git_commit == '6469e754a1':
84            return 1234
85        if git_commit == '624c3081c0':
86            return 5678
87        if git_commit == '624caaaaaa':
88            return 10000
89        return None
90
91    def timestamp_of_revision(self, path, revision):
92        return '2013-02-01 08:48:05 +0000'
93
94    def commit_locally_with_message(self, message, commit_all_working_directory_changes=True):
95        pass
96
97    def delete(self, path):
98        return self.delete_list([path])
99
100    def delete_list(self, paths):
101        if not self._filesystem:
102            return
103        for path in paths:
104            if self._filesystem.exists(path):
105                self._filesystem.remove(path)
106
107    def move(self, origin, destination):
108        if self._filesystem:
109            self._filesystem.move(self.absolute_path(origin), self.absolute_path(destination))
110
111    def changed_files(self):
112        return []
113