Tracked remote repository. Attributes: name: the name of this remote. url: the url of this remote.
| 446 | |
| 447 | |
| 448 | class Remote(object): |
| 449 | """Tracked remote repository. |
| 450 | |
| 451 | Attributes: |
| 452 | name: the name of this remote. |
| 453 | url: the url of this remote. |
| 454 | """ |
| 455 | |
| 456 | def __init__(self, git_remote, gl_repo): |
| 457 | self.git_remote = git_remote |
| 458 | self.gl_repo = gl_repo |
| 459 | self.name = self.git_remote.name |
| 460 | self.url = self.git_remote.url |
| 461 | |
| 462 | |
| 463 | # Branch-related methods |
| 464 | |
| 465 | def create_branch(self, name, head): |
| 466 | if self.lookup_branch(name): |
| 467 | raise GlError( |
| 468 | 'Branch {0} already exists in remote repository {1}'.format( |
| 469 | name, self.name)) |
| 470 | # Push won't let us push the creation of a new branch from a SHA. So we |
| 471 | # create a temporary local ref, make it point to the commit, and do the |
| 472 | # push |
| 473 | tmp_b = self.gl_repo.create_branch('gl_tmp_ref', head) |
| 474 | try: |
| 475 | git.push(self.name, '{0}:{1}'.format(tmp_b, name)) |
| 476 | return self.lookup_branch(name) |
| 477 | except ErrorReturnCode as e: |
| 478 | raise GlError(stderr(e)) |
| 479 | finally: |
| 480 | tmp_b.delete() |
| 481 | |
| 482 | def listall_branches(self): |
| 483 | """Return a list with the names of all the branches in this repository. |
| 484 | |
| 485 | Use lookup_branch if you want to get the RemoteBranch object corresponding |
| 486 | to each name. |
| 487 | """ |
| 488 | regex = re.compile(r'.*\trefs/heads/(.*)') |
| 489 | for head in stdout(git('ls-remote', '--heads', self.name)).splitlines(): |
| 490 | yield regex.match(head).group(1) |
| 491 | |
| 492 | def lookup_branch(self, branch_name): |
| 493 | if not stdout(git('ls-remote', '--heads', self.name, branch_name)): |
| 494 | return None |
| 495 | # The branch exists in the remote |
| 496 | git.fetch(self.git_remote.name, branch_name) |
| 497 | git_branch = self.gl_repo.git_repo.lookup_branch( |
| 498 | self.git_remote.name + '/' + branch_name, pygit2.GIT_BRANCH_REMOTE) |
| 499 | return RemoteBranch(git_branch, self.gl_repo) |
| 500 | |
| 501 | |
| 502 | # Tag-related methods |
| 503 | |
| 504 | def create_tag(self, name, commit): |
| 505 | if self.lookup_tag(name): |
no outgoing calls
no test coverage detected