Skip to content

openRepository

Attempt to open an already-existing repository at path.

Signature

ts
function openRepository(
  path: string,
  options?: RepositoryOpenOptions,
  signal?: AbortSignal,
): Promise<Repository>;

Parameters

  • pathrequired · string

    Directory path to repository already-existing.

  • optionsnull | RepositoryOpenOptions

    Options which can be used to configure how a repository is initialized.

    • bareboolean

      If this option is true, force opening the repository as bare event if it isn't, ignoring any working directory, and defer loading the repository configuration for performance.

    • ceilingDirsstring[]

      ceiling_dirs specifies a list of paths that the search through parent directories will stop before entering.

    • crossFsboolean

      If this option is true, the search through parent directories will not cross a filesystem boundary (detected when the stat st_dev field changes).

    • fromEnvboolean

      If this option is true, open will ignore other options and ceilingDirs, and respect the same environment variables git does. Note, however, that path overrides $GIT_DIR.

    • noDotgitboolean

      If this options is true, don't try appending /.git to path.

    • noSearchboolean

      If this option is true, the path must point directly to a repository; otherwise, this may point to a subdirectory of a repository, and open will search up through parent directories.

  • signalnull | AbortSignal

    Abort signal.

Returns

  • Promise<Repository>

    Opened repository.

Examples

Basic example.

ts
import { openRepository } from 'es-git';

const repo = await openRepository('/path/to/repo');

Open bare repository.

ts
import { openRepository } from 'es-git';

const repo = await openRepository('/path/to/repo.git', {
  bare: true,
});

Released under the MIT License.