MCPcopy Create free account
hub / github.com/libgit2/pygit2 / init_repository

Function init_repository

pygit2/__init__.py:382–459  ·  view source on GitHub ↗

Creates a new Git repository in the given *path*. If *bare* is True the repository will be bare, i.e. it will not have a working copy. The *flags* may be a combination of enums.RepositoryInitFlag constants: - BARE (overridden by the *bare* parameter) - NO_REINIT - NO_

(
    path: str | bytes | os.PathLike[str] | os.PathLike[bytes] | None,
    bare: bool = False,
    flags: enums.RepositoryInitFlag = enums.RepositoryInitFlag.MKPATH,
    mode: int | enums.RepositoryInitMode = enums.RepositoryInitMode.SHARED_UMASK,
    workdir_path: typing.Optional[str] = None,
    description: typing.Optional[str] = None,
    template_path: typing.Optional[str] = None,
    initial_head: typing.Optional[str] = None,
    origin_url: typing.Optional[str] = None,
)

Source from the content-addressed store, hash-verified

380
381
382def init_repository(
383 path: str | bytes | os.PathLike[str] | os.PathLike[bytes] | None,
384 bare: bool = False,
385 flags: enums.RepositoryInitFlag = enums.RepositoryInitFlag.MKPATH,
386 mode: int | enums.RepositoryInitMode = enums.RepositoryInitMode.SHARED_UMASK,
387 workdir_path: typing.Optional[str] = None,
388 description: typing.Optional[str] = None,
389 template_path: typing.Optional[str] = None,
390 initial_head: typing.Optional[str] = None,
391 origin_url: typing.Optional[str] = None,
392) -> Repository:
393 """
394 Creates a new Git repository in the given *path*.
395
396 If *bare* is True the repository will be bare, i.e. it will not have a
397 working copy.
398
399 The *flags* may be a combination of enums.RepositoryInitFlag constants:
400
401 - BARE (overridden by the *bare* parameter)
402 - NO_REINIT
403 - NO_DOTGIT_DIR
404 - MKDIR
405 - MKPATH (set by default)
406 - EXTERNAL_TEMPLATE
407
408 The *mode* parameter may be any of the predefined modes in
409 enums.RepositoryInitMode (SHARED_UMASK being the default), or a custom int.
410
411 The *workdir_path*, *description*, *template_path*, *initial_head* and
412 *origin_url* are all strings.
413
414 If a repository already exists at *path*, it may be opened successfully but
415 you must not rely on that behavior and should use the Repository
416 constructor directly instead.
417
418 See libgit2's documentation on git_repository_init_ext for further details.
419 """
420 # Pre-process input parameters
421 if path is None:
422 raise TypeError('Expected string type for path, found None.')
423
424 if bare:
425 flags |= enums.RepositoryInitFlag.BARE
426
427 # Options
428 options = ffi.new('git_repository_init_options *')
429 C.git_repository_init_options_init(options, C.GIT_REPOSITORY_INIT_OPTIONS_VERSION)
430 options.flags = int(flags)
431 options.mode = mode
432
433 if workdir_path:
434 workdir_path_ref = ffi.new('char []', to_bytes(workdir_path))
435 options.workdir_path = workdir_path_ref
436
437 if description:
438 description_ref = ffi.new('char []', to_bytes(description))
439 options.description = description_ref

Callers 10

test_new_repoFunction · 0.90
test_no_argFunction · 0.90
test_no_arg_aspathFunction · 0.90
test_pos_arg_falseFunction · 0.90
test_pos_arg_trueFunction · 0.90
test_keyword_arg_falseFunction · 0.90
test_keyword_arg_trueFunction · 0.90
test_discover_repoFunction · 0.90
create_repositoryFunction · 0.90

Calls 4

to_bytesFunction · 0.85
check_errorFunction · 0.85
RepositoryClass · 0.85
to_strFunction · 0.85

Tested by 10

test_new_repoFunction · 0.72
test_no_argFunction · 0.72
test_no_arg_aspathFunction · 0.72
test_pos_arg_falseFunction · 0.72
test_pos_arg_trueFunction · 0.72
test_keyword_arg_falseFunction · 0.72
test_keyword_arg_trueFunction · 0.72
test_discover_repoFunction · 0.72
create_repositoryFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…