1 # Copyright (C) 2011 Google Inc. All rights reserved.
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are
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
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.
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.
29 from webkitpy.common.system.filesystem_mock import MockFileSystem
30 from webkitpy.common.system.executive_mock import MockExecutive
33 class MockSCM(object):
34 def __init__(self, filesystem=None, executive=None):
35 self.checkout_root = "/mock-checkout"
36 self.added_paths = set()
37 self._filesystem = filesystem or MockFileSystem()
38 self._executive = executive or MockExecutive()
40 def add(self, destination_path, return_exit_code=False):
41 self.added_paths.add(destination_path)
45 def ensure_clean_working_directory(self, force_clean):
48 def supports_local_commits(self):
51 def ensure_no_local_commits(self, force_clean):
54 def exists(self, path):
55 # TestRealMain.test_real_main (and several other rebaseline tests) are sensitive to this return value.
56 # We should make those tests more robust, but for now we just return True always (since no test needs otherwise).
59 def absolute_path(self, *comps):
60 return self._filesystem.join(self.checkout_root, *comps)
62 def changed_files(self, git_commit=None):
65 def changed_files_for_revision(self, revision):
68 def head_svn_revision(self):
71 def create_patch(self, git_commit, changed_files=None):
74 def commit_ids_from_commitish_arguments(self, args):
75 return ["Commitish1", "Commitish2"]
77 def committer_email_for_revision(self, revision):
78 return "mock@webkit.org"
80 def commit_locally_with_message(self, message):
83 def commit_with_message(self, message, username=None, password=None, git_commit=None, force_squash=False, changed_files=None):
86 def merge_base(self, git_commit):
89 def commit_message_for_local_commit(self, commit_id):
90 if commit_id == "Commitish1":
91 return CommitMessage("CommitMessage1\n" \
92 "https://bugs.example.org/show_bug.cgi?id=50000\n")
93 if commit_id == "Commitish2":
94 return CommitMessage("CommitMessage2\n" \
95 "https://bugs.example.org/show_bug.cgi?id=50001\n")
96 raise Exception("Bogus commit_id in commit_message_for_local_commit.")
98 def diff_for_file(self, path, log=None):
101 def diff_for_revision(self, revision):
102 return "DiffForRevision%s\nhttp://bugs.webkit.org/show_bug.cgi?id=12345" % revision
104 def show_head(self, path):
107 def svn_revision_from_commit_text(self, commit_text):
110 def delete(self, path):
111 if not self._filesystem:
113 if self._filesystem.exists(path):
114 self._filesystem.remove(path)