MCPcopy
hub / github.com/gitless-vcs/gitless / init_repository

Function init_repository

gitless/core.py:68–99  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

66
67
68def 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
102class Repository(object):

Callers

nothing calls this directly

Calls 7

create_branchMethod · 0.95
error_on_noneFunction · 0.85
GlErrorClass · 0.85
RepositoryClass · 0.85
stderrFunction · 0.70
lookup_branchMethod · 0.45
listall_branchesMethod · 0.45

Tested by

no test coverage detected