Module: Git::Factories Private
- Included in:
- Git
- Defined in:
- lib/git/factories.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Implementation of the Git module factory entry points
Provides .open, .init, .clone, and .bare — the four methods that
construct a Repository. Extended onto the Git module so that
Git.open(...), Git.init(...), etc. resolve here.
Instance Method Summary collapse
-
#bare(git_dir, options = {}) ⇒ Git::Repository
Open an existing bare repository at
git_dir. -
#clone(repository_url, directory = nil, options = {}) ⇒ Git::Repository
Clone a repository into a new directory.
-
#init(directory = '.', options = {}) ⇒ Git::Repository
Create an empty Git repository or reinitialize an existing one.
-
#open(working_dir, options = {}) ⇒ Git::Repository
Open a working copy at an existing path.
Instance Method Details
#bare(git_dir, options = {}) ⇒ Git::Repository
Open an existing bare repository at git_dir
432 433 434 435 436 437 |
# File 'lib/git/factories.rb', line 432 def (git_dir, = {}) reject_unknown_option_keys!(.keys, BARE_ALLOWED_OPTS) paths = resolve_repository_paths(git_dir, bare: true, index: [:index]) from_paths(, paths) end |
#clone(repository_url, directory = nil, options = {}) ⇒ Git::Repository
If git fails before the transfer completes, git removes directory
and the separate git directory it created, or empties directory when
it existed before the call. A :repository path that already exists is
refused before the transfer starts. If the transfer completes but the
checkout fails, or the :timeout or the global timeout kills git, what
git wrote is left in place. If UnexpectedResultError is raised,
the completed clone is left in place.
Clone a repository into a new directory
231 232 233 234 235 236 237 238 |
# File 'lib/git/factories.rb', line 231 def clone(repository_url, directory = nil, = {}) opts, context_opts = () directory = (directory, bare: context_opts[:bare], base: opts[:chdir]) if directory clone_result = run_clone_command(repository_url, directory, opts, context_opts) paths = resolve_paths_from_clone_result(clone_result, directory, opts, context_opts) from_paths((context_opts), paths) end |
#init(directory = '.', options = {}) ⇒ Git::Repository
If git exits non-zero after it starts writing, whatever it wrote is
left in place: directory when git created it, and a git directory
(.git, or the :repository path and the gitfile pointing at it) that
git may not recognize as a repository. If git succeeds but the
repository cannot be opened, the initialized repository is left in place.
Create an empty Git repository or reinitialize an existing one
314 315 316 317 318 319 320 321 |
# File 'lib/git/factories.rb', line 314 def init(directory = '.', = {}) reject_unknown_option_keys!(.keys, INIT_ALLOWED_OPTS) = () directory = (directory, bare: [:bare]) run_init_command(directory, ) open_after_init(directory, ) end |
#open(working_dir, options = {}) ⇒ Git::Repository
This method opens working copies only. To open a bare repository, use
Git.bare.
Open a working copy at an existing path
378 379 380 381 382 383 384 385 386 387 388 389 390 |
# File 'lib/git/factories.rb', line 378 def open(working_dir, = {}) reject_unknown_option_keys!(.keys, OPEN_ALLOWED_OPTS) = PathResolver.(working_dir, PathResolver::WORKING_DIRECTORY_MESSAGE) raise ArgumentError, "'#{working_dir}' is not a directory" unless Dir.exist?() working_dir = [:repository] ? : resolve_open_working_dir(, ) paths = resolve_repository_paths( working_dir, bare: false, repository: [:repository], index: [:index] ) from_paths(, paths) end |