github.com/gfleury/gobbs@v0.0.0-20200831213239-44ca2b94c1a1/search/mocked_responses/SearchCode.json (about) 1 { 2 "scope": { 3 "type": "GLOBAL" 4 }, 5 "code": { 6 "category": "primary", 7 "isLastPage": true, 8 "count": 187, 9 "start": 0, 10 "nextStart": 25, 11 "values": [ 12 { 13 "repository": { 14 "slug": "repository", 15 "id": 365, 16 "name": "repository", 17 "scmId": "git", 18 "state": "AVAILABLE", 19 "statusMessage": "Available", 20 "forkable": true, 21 "project": { 22 "key": "PROJECT", 23 "id": 1, 24 "name": "Project One", 25 "description": "Misc utilities .", 26 "public": false, 27 "type": "NORMAL", 28 "avatarUrl": "/projects/UTIL/avatar.png?s=64&v=1451399004000" 29 }, 30 "public": false 31 }, 32 "file": "git.py", 33 "hitContexts": [ 34 [ 35 { 36 "line": 5, 37 "text": "" 38 }, 39 { 40 "line": 6, 41 "text": "from <em>git</em> import Repo, <em>Git</em>" 42 }, 43 { 44 "line": 7, 45 "text": "from <em>git</em>.exc import <em>Git</em>Error" 46 }, 47 { 48 "line": 8, 49 "text": "" 50 }, 51 { 52 "line": 9, 53 "text": "from git import <em>Git</em>UtilError" 54 }, 55 { 56 "line": 10, 57 "text": "" 58 }, 59 { 60 "line": 11, 61 "text": "" 62 }, 63 { 64 "line": 12, 65 "text": "def checkout(local_path, branch=None, ssh_key=None, allow_overwrite=False, allow_remote_checkout=True," 66 }, 67 { 68 "line": 13, 69 "text": " remote_path=None):" 70 }, 71 { 72 "line": 14, 73 "text": " if Path(local_path).exists():" 74 }, 75 { 76 "line": 15, 77 "text": "" 78 }, 79 { 80 "line": 16, 81 "text": " try:" 82 }, 83 { 84 "line": 17, 85 "text": " repo = Repo(local_path)" 86 }, 87 { 88 "line": 18, 89 "text": " except <em>Git</em>Error:" 90 }, 91 { 92 "line": 19, 93 "text": " if allow_overwrite and allow_remote_checkout:" 94 }, 95 { 96 "line": 20, 97 "text": " shutil.rmtree(local_path, ignore_errors=True)" 98 }, 99 { 100 "line": 21, 101 "text": " <em>clone</em>_remote(remote_path, local_path, branch, ssh_key)" 102 }, 103 { 104 "line": 22, 105 "text": " return" 106 }, 107 { 108 "line": 23, 109 "text": " else:" 110 }, 111 { 112 "line": 24, 113 "text": " raise <em>Git</em>UtilError("Path '%s' already exists and is not a valid <em>git</em> repo. " % local_path +" 114 }, 115 { 116 "line": 25, 117 "text": " "Either allow_overwrite or allow_remote_checkout is set to False.")" 118 }, 119 { 120 "line": 26, 121 "text": "" 122 }, 123 { 124 "line": 27, 125 "text": " if branch:" 126 }, 127 { 128 "line": 28, 129 "text": " try:" 130 }, 131 { 132 "line": 29, 133 "text": " <em>git</em>_branch = None" 134 }, 135 { 136 "line": 30, 137 "text": "" 138 }, 139 { 140 "line": 31, 141 "text": " for local_branch in repo.heads:" 142 }, 143 { 144 "line": 32, 145 "text": " if local_branch.name == branch:" 146 }, 147 { 148 "line": 33, 149 "text": " <em>git</em>_branch = local_branch" 150 }, 151 { 152 "line": 34, 153 "text": "" 154 }, 155 { 156 "line": 35, 157 "text": " <em>git</em>_branch = <em>git</em>_branch or repo.create_head(branch)" 158 }, 159 { 160 "line": 36, 161 "text": "" 162 }, 163 { 164 "line": 37, 165 "text": " if repo.active_branch != <em>git</em>_branch:" 166 }, 167 { 168 "line": 38, 169 "text": " if allow_overwrite" 170 } 171 ], 172 [ 173 { 174 "line": 38, 175 "text": ":" 176 }, 177 { 178 "line": 39, 179 "text": " <em>git</em>_branch.checkout()" 180 }, 181 { 182 "line": 40, 183 "text": " else:" 184 }, 185 { 186 "line": 41, 187 "text": " raise <em>Git</em>UtilError("Path '%s' already exists and is a a valid <em>git</em> repo, " % local_path +" 188 }, 189 { 190 "line": 42, 191 "text": " "but another branch is active and allow_overwrite is set to False")" 192 }, 193 { 194 "line": 43, 195 "text": "" 196 }, 197 { 198 "line": 44, 199 "text": " except <em>Git</em>Error as error:" 200 }, 201 { 202 "line": 45, 203 "text": " raise <em>Git</em>UtilError(str(error))" 204 }, 205 { 206 "line": 46, 207 "text": "" 208 }, 209 { 210 "line": 47, 211 "text": " repo.remotes.origin.pull()" 212 }, 213 { 214 "line": 48, 215 "text": "" 216 }, 217 { 218 "line": 49, 219 "text": " else:" 220 }, 221 { 222 "line": 50, 223 "text": " if allow_remote_checkout and remote_path:" 224 }, 225 { 226 "line": 51, 227 "text": " <em>clone</em>_remote(remote_path, local_path, branch, ssh_key)" 228 }, 229 { 230 "line": 52, 231 "text": " else:" 232 }, 233 { 234 "line": 53, 235 "text": " raise <em>Git</em>UtilError("Path '%s' does not exist. Could not <em>clone</em> remote, either because " % local_path +" 236 }, 237 { 238 "line": 54, 239 "text": " "allow_remote_checkout is set to False, or no remote URL is provided")" 240 }, 241 { 242 "line": 55, 243 "text": "" 244 }, 245 { 246 "line": 56, 247 "text": "" 248 }, 249 { 250 "line": 57, 251 "text": "def <em>clone</em>_remote(remote_path, local_path, branch=None, ssh_key=None):" 252 }, 253 { 254 "line": 58, 255 "text": " '''" 256 }, 257 { 258 "line": 59, 259 "text": " <em>Clone</em> a remote repo to a local path" 260 }, 261 { 262 "line": 60, 263 "text": " :param remote_path: the remote URL;)" 264 }, 265 { 266 "line": 61, 267 "text": " :param local_path: the local URL (e.g. '/home/username/work/table-precomp')" 268 }, 269 { 270 "line": 62, 271 "text": " :param branch: the branch to checkout (e.g. 'TAPI-xxx_optimizing_performance')" 272 }, 273 { 274 "line": 63, 275 "text": " :param ssh_key: the path to your local ssh identity key for the remote repo" 276 }, 277 { 278 "line": 64, 279 "text": " '''" 280 }, 281 { 282 "line": 65, 283 "text": "" 284 }, 285 { 286 "line": 66, 287 "text": " def __<em>clone</em>_remote(remote_path, local_path, branch=None):" 288 }, 289 { 290 "line": 67, 291 "text": " try:" 292 }, 293 { 294 "line": 68, 295 "text": " Repo.<em>clone</em>_from(remote_path, local_path, branch=branch or 'master')" 296 }, 297 { 298 "line": 69, 299 "text": " except <em>Git</em>Error as error:" 300 }, 301 { 302 "line": 70, 303 "text": " raise <em>Git</em>UtilError(str(error))" 304 }, 305 { 306 "line": 71, 307 "text": "" 308 }, 309 { 310 "line": 72, 311 "text": " if ssh_key:" 312 }, 313 { 314 "line": 73, 315 "text": " <em>git</em>_ssh_cmd = 'ssh -i %s' % ssh_key" 316 }, 317 { 318 "line": 74, 319 "text": " with <em>Git</em>().custom_environment(<em>GIT</em>_SSH_COMMAND=<em>git</em>_ssh_cmd):" 320 }, 321 { 322 "line": 75, 323 "text": " __<em>clone</em>_remote(remote_path, local_path, branch)" 324 }, 325 { 326 "line": 76, 327 "text": " else:" 328 }, 329 { 330 "line": 77, 331 "text": " __<em>clone</em>_remote(remote_path, local_path, branch)" 332 } 333 ] 334 ], 335 "hitCount": 36 336 } 337 ] 338 }, 339 "query": { 340 "substituted": false 341 } 342 }