| OLD | NEW |
| (Empty) |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 from webkitpy.common.system.filesystem_mock import MockFileSystem | |
| 6 from webkitpy.common.system.executive_mock import MockExecutive | |
| 7 | |
| 8 | |
| 9 class MockGit(object): | |
| 10 | |
| 11 # Arguments are listed below, even if they're unused, in order to match | |
| 12 # the Git class. pylint: disable=unused-argument | |
| 13 | |
| 14 executable_name = 'mock-git' | |
| 15 | |
| 16 def __init__(self, cwd=None, filesystem=None, executive=None): | |
| 17 self.checkout_root = '/mock-checkout' | |
| 18 self.cwd = cwd or self.checkout_root | |
| 19 self.added_paths = set() | |
| 20 self._filesystem = filesystem or MockFileSystem() | |
| 21 self._executive = executive or MockExecutive() | |
| 22 self._local_commits = [] | |
| 23 | |
| 24 def add_all(self, pathspec=None): | |
| 25 if not pathspec: | |
| 26 pathspec = self.checkout_root | |
| 27 for path in self._filesystem.glob(pathspec): | |
| 28 self.add_list(self._filesystem.files_under(path)) | |
| 29 | |
| 30 def add(self, destination_path, return_exit_code=False): | |
| 31 self.add_list([destination_path], return_exit_code) | |
| 32 | |
| 33 def add_list(self, destination_paths, return_exit_code=False): | |
| 34 self.added_paths.update(set(destination_paths)) | |
| 35 if return_exit_code: | |
| 36 return 0 | |
| 37 | |
| 38 def has_working_directory_changes(self, pathspec=None): | |
| 39 return False | |
| 40 | |
| 41 def ensure_cleanly_tracking_remote_master(self): | |
| 42 pass | |
| 43 | |
| 44 def current_branch(self): | |
| 45 return "mock-branch-name" | |
| 46 | |
| 47 def current_branch_or_ref(self): | |
| 48 return "mock-branch-name" | |
| 49 | |
| 50 def checkout_branch(self, name): | |
| 51 pass | |
| 52 | |
| 53 def create_clean_branch(self, name): | |
| 54 pass | |
| 55 | |
| 56 def delete_branch(self, name): | |
| 57 pass | |
| 58 | |
| 59 def supports_local_commits(self): | |
| 60 return True | |
| 61 | |
| 62 def exists(self, path): | |
| 63 # TestRealMain.test_real_main (and several other rebaseline tests) are s
ensitive to this return value. | |
| 64 # We should make those tests more robust, but for now we just return Tru
e always (since no test needs otherwise). | |
| 65 return True | |
| 66 | |
| 67 def absolute_path(self, *comps): | |
| 68 return self._filesystem.join(self.checkout_root, *comps) | |
| 69 | |
| 70 def commit_position(self, path): | |
| 71 return 5678 | |
| 72 | |
| 73 def commit_position_from_git_commit(self, git_commit): | |
| 74 if git_commit == '6469e754a1': | |
| 75 return 1234 | |
| 76 if git_commit == '624c3081c0': | |
| 77 return 5678 | |
| 78 if git_commit == '624caaaaaa': | |
| 79 return 10000 | |
| 80 return None | |
| 81 | |
| 82 def timestamp_of_revision(self, path, revision): | |
| 83 return '2013-02-01 08:48:05 +0000' | |
| 84 | |
| 85 def commit_locally_with_message(self, message): | |
| 86 self._local_commits.append([message]) | |
| 87 | |
| 88 def local_commits(self): | |
| 89 """Returns the internal recording of commits made via |commit_locally_wi
th_message|. | |
| 90 | |
| 91 This is a testing convenience method; commits are formatted as: | |
| 92 [ message, commit_all_working_directory_changes, author ]. | |
| 93 """ | |
| 94 return self._local_commits | |
| 95 | |
| 96 def delete(self, path): | |
| 97 return self.delete_list([path]) | |
| 98 | |
| 99 def delete_list(self, paths): | |
| 100 if not self._filesystem: | |
| 101 return | |
| 102 for path in paths: | |
| 103 if self._filesystem.exists(path): | |
| 104 self._filesystem.remove(path) | |
| 105 | |
| 106 def move(self, origin, destination): | |
| 107 if self._filesystem: | |
| 108 self._filesystem.move(self.absolute_path(origin), self.absolute_path
(destination)) | |
| 109 | |
| 110 def changed_files(self): | |
| 111 return [] | |
| 112 | |
| 113 def unstaged_changes(self): | |
| 114 return {} | |
| OLD | NEW |