(type, url, target_name, revision = None, try_only_local_operations = False)
| 117 | return path.replace("\\ ", " ") |
| 118 | |
| 119 | def cloneRepository(type, url, target_name, revision = None, try_only_local_operations = False): |
| 120 | target_dir = escapifyPath(os.path.join(SRC_DIR, target_name)) |
| 121 | target_dir_exists = os.path.exists(target_dir) |
| 122 | log("Cloning " + url + " to " + target_dir) |
| 123 | |
| 124 | if type == "hg": |
| 125 | repo_exists = os.path.exists(os.path.join(target_dir, ".hg")) |
| 126 | |
| 127 | if not repo_exists: |
| 128 | if try_only_local_operations: |
| 129 | raise RuntimeError("Repository for " + target_name + " not found; cannot execute local operations only") |
| 130 | if target_dir_exists: |
| 131 | dlog("Removing directory " + target_dir + " before cloning") |
| 132 | shutil.rmtree(target_dir) |
| 133 | dieIfNonZero(executeCommand(TOOL_COMMAND_HG + " clone " + url + " " + target_dir)) |
| 134 | elif not try_only_local_operations: |
| 135 | log("Repository " + target_dir + " already exists; pulling instead of cloning") |
| 136 | dieIfNonZero(executeCommand(TOOL_COMMAND_HG + " pull -R " + target_dir)) |
| 137 | |
| 138 | if revision is None: |
| 139 | revision = "" |
| 140 | dieIfNonZero(executeCommand(TOOL_COMMAND_HG + " update -R " + target_dir + " -C " + revision)) |
| 141 | dieIfNonZero(executeCommand(TOOL_COMMAND_HG + " purge -R " + target_dir + " --config extensions.purge=")) |
| 142 | |
| 143 | elif type == "git": |
| 144 | repo_exists = os.path.exists(os.path.join(target_dir, ".git")) |
| 145 | |
| 146 | if not repo_exists: |
| 147 | if try_only_local_operations: |
| 148 | raise RuntimeError("Repository for " + target_name + " not found; cannot execute local operations only") |
| 149 | if target_dir_exists: |
| 150 | dlog("Removing directory " + target_dir + " before cloning") |
| 151 | shutil.rmtree(target_dir) |
| 152 | dieIfNonZero(executeCommand(TOOL_COMMAND_GIT + " clone --recursive " + url + " " + target_dir)) |
| 153 | elif not try_only_local_operations: |
| 154 | log("Repository " + target_dir + " already exists; fetching instead of cloning") |
| 155 | dieIfNonZero(executeCommand(TOOL_COMMAND_GIT + " -C " + target_dir + " fetch --recurse-submodules")) |
| 156 | |
| 157 | if revision is None: |
| 158 | revision = "HEAD" |
| 159 | dieIfNonZero(executeCommand(TOOL_COMMAND_GIT + " -C " + target_dir + " reset --hard " + revision)) |
| 160 | dieIfNonZero(executeCommand(TOOL_COMMAND_GIT + " -C " + target_dir + " clean -fxd")) |
| 161 | |
| 162 | elif type == "svn": |
| 163 | if not try_only_local_operations: # we can't do much without a server connection when dealing with SVN |
| 164 | if target_dir_exists: |
| 165 | dlog("Removing directory " + target_dir + " before cloning") |
| 166 | shutil.rmtree(target_dir) |
| 167 | dieIfNonZero(executeCommand(TOOL_COMMAND_SVN + " checkout " + url + " " + target_dir)) |
| 168 | |
| 169 | if revision is not None and revision != "": |
| 170 | raise RuntimeError("Updating to revision not implemented for SVN.") |
| 171 | |
| 172 | else: |
| 173 | raise ValueError("Cloning " + type + " repositories not implemented.") |
| 174 | |
| 175 | |
| 176 | def decompressTarXZFile(src_filename, dst_filename): |
no test coverage detected