tizen beta release
[profile/ivi/webkit-efl.git] / Tools / Scripts / webkitpy / common / checkout / scm / scm_mock.py
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
29 from webkitpy.common.system.filesystem_mock import MockFileSystem
30 from webkitpy.common.system.executive_mock import MockExecutive
31
32
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()
39
40     def add(self, destination_path, return_exit_code=False):
41         self.added_paths.add(destination_path)
42         if return_exit_code:
43             return 0
44
45     def ensure_clean_working_directory(self, force_clean):
46         pass
47
48     def supports_local_commits(self):
49         return True
50
51     def ensure_no_local_commits(self, force_clean):
52         pass
53
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).
57         return True
58
59     def absolute_path(self, *comps):
60         return self._filesystem.join(self.checkout_root, *comps)
61
62     def changed_files(self, git_commit=None):
63         return ["MockFile1"]
64
65     def changed_files_for_revision(self, revision):
66         return ["MockFile1"]
67
68     def head_svn_revision(self):
69         return 1234
70
71     def create_patch(self, git_commit, changed_files=None):
72         return "Patch1"
73
74     def commit_ids_from_commitish_arguments(self, args):
75         return ["Commitish1", "Commitish2"]
76
77     def committer_email_for_revision(self, revision):
78         return "mock@webkit.org"
79
80     def commit_locally_with_message(self, message):
81         pass
82
83     def commit_with_message(self, message, username=None, password=None, git_commit=None, force_squash=False, changed_files=None):
84         pass
85
86     def merge_base(self, git_commit):
87         return None
88
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.")
97
98     def diff_for_file(self, path, log=None):
99         return path + '-diff'
100
101     def diff_for_revision(self, revision):
102         return "DiffForRevision%s\nhttp://bugs.webkit.org/show_bug.cgi?id=12345" % revision
103
104     def show_head(self, path):
105         return path
106
107     def svn_revision_from_commit_text(self, commit_text):
108         return "49824"
109
110     def delete(self, path):
111         if not self._filesystem:
112             return
113         if self._filesystem.exists(path):
114             self._filesystem.remove(path)