Creates a new Gitless's repository in the cwd. Args: url: if given the local repository will be a clone of the remote repository given by this url.
(url=None)
| 66 | |
| 67 | |
| 68 | def init_repository(url=None): |
| 69 | """Creates a new Gitless's repository in the cwd. |
| 70 | |
| 71 | Args: |
| 72 | url: if given the local repository will be a clone of the remote repository |
| 73 | given by this url. |
| 74 | """ |
| 75 | cwd = os.getcwd() |
| 76 | try: |
| 77 | error_on_none(pygit2.discover_repository(cwd)) |
| 78 | raise GlError('You are already in a Gitless repository') |
| 79 | except KeyError: # Expected |
| 80 | if not url: |
| 81 | repo = pygit2.init_repository(cwd) |
| 82 | # We also create an initial root commit |
| 83 | git.commit(allow_empty=True, m='Initialize repository') |
| 84 | return repo |
| 85 | |
| 86 | try: |
| 87 | git.clone(url, cwd) |
| 88 | except ErrorReturnCode as e: |
| 89 | raise GlError(stderr(e)) |
| 90 | |
| 91 | # We get all remote branches as well and create local equivalents |
| 92 | repo = Repository() |
| 93 | remote = repo.remotes['origin'] |
| 94 | for rb in (remote.lookup_branch(bn) for bn in remote.listall_branches()): |
| 95 | if rb.branch_name == 'master': |
| 96 | continue |
| 97 | new_b = repo.create_branch(rb.branch_name, rb.head) |
| 98 | new_b.upstream = rb |
| 99 | return repo |
| 100 | |
| 101 | |
| 102 | class Repository(object): |
nothing calls this directly
no test coverage detected