Class Gitlab::Git::Repository
In: lib/gitlab_git/repository.rb
Parent: Object

Methods

Included Modules

Gitlab::Git::Popen

Classes and Modules

Class Gitlab::Git::Repository::InvalidBlobName
Class Gitlab::Git::Repository::InvalidRef
Class Gitlab::Git::Repository::NoRepository

Constants

SEARCH_CONTEXT_LINES = 3
AUTOCRLF_VALUES = { "true" => true, "false" => false, "input" => :input

Attributes

name  [R]  Directory name of repo
path  [R]  Full path to repo
rugged  [R]  Rugged repo object

Public Class methods

‘path’ must be the path to a bare git repository, e.g. /path/to/my-repo.git

Public Instance methods

Returns the Git attributes for the given file path.

See `Gitlab::Git::Attributes` for more information.

Returns the number of valid branches

Returns true if the given branch exists

name - The name of the branch as a String.

Returns an Array of branch names sorted by name ASC

Returns branch names collection that contains the special commit(SHA1 or name)

Ex.

  repo.branch_names_contains('master')

Returns an Array of Branches

Returns branch collection that contains the special commit(SHA1 or name)

Ex.

  repo.branch_names_contains('master')

Check out the specified ref. Valid options are:

 :b - Create a new branch at +start_point+ and set HEAD to the new
      branch.

 * These options are passed to the Rugged::Repository#checkout method:

 :progress ::
   A callback that will be executed for checkout progress notifications.
   Up to 3 parameters are passed on each execution:

   - The path to the last updated file (or +nil+ on the very first
     invocation).
   - The number of completed checkout steps.
   - The number of total checkout steps to be performed.

 :notify ::
   A callback that will be executed for each checkout notification
   types specified with +:notify_flags+. Up to 5 parameters are passed
   on each execution:

   - An array containing the +:notify_flags+ that caused the callback
     execution.
   - The path of the current file.
   - A hash describing the baseline blob (or +nil+ if it does not
     exist).
   - A hash describing the target blob (or +nil+ if it does not exist).
   - A hash describing the workdir blob (or +nil+ if it does not
     exist).

 :strategy ::
   A single symbol or an array of symbols representing the strategies
   to use when performing the checkout. Possible values are:

   :none ::
     Perform a dry run (default).

   :safe ::
     Allow safe updates that cannot overwrite uncommitted data.

   :safe_create ::
     Allow safe updates plus creation of missing files.

   :force ::
     Allow all updates to force working directory to look like index.

   :allow_conflicts ::
     Allow checkout to make safe updates even if conflicts are found.

   :remove_untracked ::
     Remove untracked files not in index (that are not ignored).

   :remove_ignored ::
     Remove ignored files not in index.

   :update_only ::
     Only update existing files, don't create new ones.

   :dont_update_index ::
     Normally checkout updates index entries as it goes; this stops
     that.

   :no_refresh ::
     Don't refresh index/config/etc before doing checkout.

   :disable_pathspec_match ::
     Treat pathspec as simple list of exact match file paths.

   :skip_locked_directories ::
     Ignore directories in use, they will be left empty.

   :skip_unmerged ::
     Allow checkout to skip unmerged files (NOT IMPLEMENTED).

   :use_ours ::
     For unmerged files, checkout stage 2 from index (NOT IMPLEMENTED).

   :use_theirs ::
     For unmerged files, checkout stage 3 from index (NOT IMPLEMENTED).

   :update_submodules ::
     Recursively checkout submodules with same options (NOT
     IMPLEMENTED).

   :update_submodules_if_changed ::
     Recursively checkout submodules if HEAD moved in super repo (NOT
     IMPLEMENTED).

 :disable_filters ::
   If +true+, filters like CRLF line conversion will be disabled.

 :dir_mode ::
   Mode for newly created directories. Default: +0755+.

 :file_mode ::
   Mode for newly created files. Default: +0755+ or +0644+.

 :file_open_flags ::
   Mode for opening files. Default:
   <code>IO::CREAT | IO::TRUNC | IO::WRONLY</code>.

 :notify_flags ::
   A single symbol or an array of symbols representing the cases in
   which the +:notify+ callback should be invoked. Possible values are:

   :none ::
     Do not invoke the +:notify+ callback (default).

   :conflict ::
     Invoke the callback for conflicting paths.

   :dirty ::
     Invoke the callback for "dirty" files, i.e. those that do not need
     an update but no longer match the baseline.

   :updated ::
     Invoke the callback for any file that was changed.

   :untracked ::
     Invoke the callback for untracked files.

   :ignored ::
     Invoke the callback for ignored files.

   :all ::
     Invoke the callback for all these cases.

 :paths ::
   A glob string or an array of glob strings specifying which paths
   should be taken into account for the checkout operation. +nil+ will
   match all files.  Default: +nil+.

 :baseline ::
   A Rugged::Tree that represents the current, expected contents of the
   workdir.  Default: +HEAD+.

 :target_directory ::
   A path to an alternative workdir directory in which the checkout
   should be performed.

Mimic the `git clean` command and recursively delete untracked files. Valid keys that can be passed in the options hash are:

:d - Remove untracked directories :f - Remove untracked directories that are managed by a different

     repository

:x - Remove ignored files

The value in options must evaluate to true for an option to take effect.

Examples:

  repo.clean(d: true, f: true) # Enable the -d and -f options

  repo.clean(d: false, x: true) # -x is enabled, -d is not

Return total commits count accessible from passed ref

Return a collection of Rugged::Commits between the two revspec arguments. See git-scm.com/docs/git-rev-parse.html#_specifying_revisions for a detailed list of valid arguments.

Counts the amount of commits between `from` and `to`.

Create a new branch named **ref+ based on **stat_point+, HEAD by default

Examples:

  create_branch("feature")
  create_branch("other-feature", "master")

Delete the specified branch from the repository

Return an array of Diff objects that represent the diff between from and to. See Diff::filter_diff_options for the allowed diff options. The options hash can also include :break_rewrites to split larger rewrites into delete/add pairs.

Return the diff between from and to in a single patch string. The options hash has the same allowed keys as diff.

Checks if the blob should be diffable according to its attributes

Discovers the default branch based on the repository‘s available branches

  • If no branches are present, returns nil
  • If one branch is present, returns its name
  • If two or more branches are present, returns current HEAD or master or first branch

Fetch the specified remote

Directly find a branch with a simple name (e.g. master)

force_reload causes a new Rugged repository to be instantiated

This is to work around a bug in libgit2 that causes in-memory refs to be stale/invalid when packed-refs is changed. See gitlab.com/gitlab-org/gitlab-ce/issues/15392#note_14538333

Returns commits collection

Ex.

  repo.find_commits(
    ref: 'master',
    max_count: 10,
    skip: 5,
    order: :date
  )

  +options+ is a Hash of optional arguments to git
    :ref is the ref from which to begin (SHA1 or name)
    :contains is the commit contained by the refs from which to begin (SHA1 or name)
    :max_count is the maximum number of commits to fetch
    :skip is the number of commits to skip
    :order is the commits order and allowed value is :date(default) or :topo

Deprecated. Will be removed in 5.2

Use the Rugged Walker API to build an array of commits.

Usage.

  repo.log(
    ref: 'master',
    path: 'app/models',
    limit: 10,
    offset: 5,
    after: Time.new(2016, 4, 21, 14, 32, 10)
  )

Lookup for rugged object by oid or ref name

Returns result like "git ls-files" , recursive and full file path

Ex.

  repo.ls_files('master')

Merge the source_name branch into the target_name branch. This is equivalent to `git merge —no_ff source_name`, since a merge commit is always created.

Returns the SHA of the most recent common ancestor of from and to

Create a new directory with a .gitkeep file. Creates all required nested directories (i.e. mkdir -p behavior)

options should contain next structure:

  author: {
    email: 'user@example.com',
    name: 'Test User',
    time: Time.now
  },
  committer: {
    email: 'user@example.com',
    name: 'Test User',
    time: Time.now
  },
  commit: {
    message: 'Wow such commit',
    branch: 'master',
    update_ref: false
  }

Push +*refspecs+ to the remote identified by remote_name.

Alias to old method for compatibility

Returns an Array of branch and tag names

Get refs hash which key is SHA1 and value is a Rugged::Reference

Add a new remote to this repository. Returns a Rugged::Remote object

Delete the specified remote from this repository.

Return an array of this repository‘s remote names

Update the specified remote using the values in the options hash

Example repo.update_remote("origin", url: "path/to/repo")

Sets HEAD to the commit specified by ref; ref can be a branch or tag name or a commit SHA. Valid reset_type values are:

 [:soft]
   the head will be moved to the commit.
 [:mixed]
   will trigger a +:soft+ reset, plus the index will be replaced
   with the content of the commit tree.
 [:hard]
   will trigger a +:mixed+ reset and the working directory will be
   replaced with the content of the index. (Untracked and ignored files
   will be left alone)

Return the object that revspec points to. If revspec is an annotated tag, then return the tag‘s target instead.

Default branch in the repository

Returns an array of BlobSnippets for files at the specified ref that contain the query string.

Return repo size in megabytes

Return hash with submodules info for this repository

Ex.

  {
    "rack"  => {
      "id" => "c67be4624545b4263184c4a0e8f887efd0a66320",
      "path" => "rack",
      "url" => "git://github.com/chneukirchen/rack.git"
    },
    "encoding" => {
      "id" => ....
    }
  }

Returns true if the given tag exists

name - The name of the tag as a String.

Returns an Array of tag names

Returns an Array of Tags

[Validate]