Class: Gitlab::Git::Repository
- Inherits:
-
Object
- Object
- Gitlab::Git::Repository
- Includes:
- EncodingHelper, RepositoryMirroring, WrapsGitalyErrors, Utils::StrongMemoize
- Defined in:
- lib/gitlab/git/repository.rb
Defined Under Namespace
Classes: CreateTreeError
Constant Summary collapse
- SEARCH_CONTEXT_LINES =
3- REV_LIST_COMMIT_LIMIT =
2_000- GITALY_INTERNAL_URL =
'ssh://gitaly/internal.git'- GITLAB_PROJECTS_TIMEOUT =
Gitlab.config.gitlab_shell.git_timeout
- EMPTY_REPOSITORY_CHECKSUM =
'0000000000000000000000000000000000000000'- DEFAULT_LOG_OPTIONS =
{ limit: 10, offset: 0, path: nil, author: nil, follow: false, skip_merges: false, after: nil, before: nil, all: false, message_regex: nil }.freeze
- NoRepository =
Class.new(::Gitlab::Git::BaseError)
- CommitNotFound =
Class.new(::Gitlab::Git::BaseError)
- RepositoryExists =
Class.new(::Gitlab::Git::BaseError)
- InvalidRepository =
Class.new(::Gitlab::Git::BaseError)
- InvalidBlobName =
Class.new(::Gitlab::Git::BaseError)
- InvalidRef =
Class.new(::Gitlab::Git::BaseError)
- GitError =
Class.new(::Gitlab::Git::BaseError)
- DeleteBranchError =
Class.new(::Gitlab::Git::BaseError)
- TagExistsError =
Class.new(::Gitlab::Git::BaseError)
- ChecksumError =
Class.new(::Gitlab::Git::BaseError)
Constants included from EncodingHelper
EncodingHelper::BOM_UTF8, EncodingHelper::ENCODING_CONFIDENCE_THRESHOLD, EncodingHelper::ESCAPED_CHARS, EncodingHelper::UNICODE_REPLACEMENT_CHARACTER
Instance Attribute Summary collapse
-
#container ⇒ Object
readonly
Returns the value of attribute container.
-
#gl_project_path ⇒ Object
readonly
Returns the value of attribute gl_project_path.
-
#gl_repository ⇒ Object
(also: #object_pool_remote_name)
readonly
Returns the value of attribute gl_repository.
-
#name ⇒ Object
readonly
Directory name of repo.
-
#relative_path ⇒ Object
readonly
Relative path of repo.
-
#storage ⇒ Object
readonly
Returns the value of attribute storage.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #add_branch(branch_name, user:, target:, skip_ci: false) ⇒ Object
- #add_tag(tag_name, user:, target:, message: nil) ⇒ Object
-
#ancestor?(from, to) ⇒ Boolean
Returns true is
fromis direct ancestor toto, otherwise false. - #archive_metadata(ref, storage_path, project_path, format = "tar.gz", append_sha:, path: nil) ⇒ Object
- #async_delete_refs(*refs) ⇒ Object
-
#attributes(path) ⇒ Object
Returns the Git attributes for the given file path.
-
#attributes_at(ref) ⇒ Object
Returns parsed .gitattributes for a given ref.
-
#batch_blobs(items, blob_size_limit: Gitlab::Git::Blob::MAX_DATA_DISPLAY_SIZE) ⇒ Object
Items should be of format [[commit_id, path], [commit_id1, path1]].
- #blob_at(sha, path, limit: Gitlab::Git::Blob::MAX_DATA_DISPLAY_SIZE) ⇒ Object
-
#blobs(revisions, with_paths: false, dynamic_timeout: nil) ⇒ Object
List blobs reachable via a set of revisions.
-
#branch_count ⇒ Object
Returns the number of valid branches.
-
#branch_exists?(name) ⇒ Boolean
Returns true if the given branch exists.
-
#branch_names ⇒ Object
Returns an Array of branch names sorted by name ASC.
- #branch_names_contains_sha(sha, limit: 0) ⇒ Object
-
#branches ⇒ Object
Returns an Array of Branches.
- #bundle_to_disk(save_path) ⇒ Object
- #can_be_merged?(source_sha, target_branch) ⇒ Boolean
- #check_objects_exist(refs) ⇒ Object
- #checksum ⇒ Object
-
#cherry_pick ⇒ Object
rubocop:enable Metrics/ParameterLists.
-
#clean(options = {}) ⇒ Object
Mimic the ‘git clean` command and recursively delete untracked files.
-
#commit(ref = 'HEAD') ⇒ Object
Refactoring aid; allows us to copy code from app/models/repository.rb.
-
#commit_count(ref) ⇒ Object
Return total commits count accessible from passed ref.
-
#commit_files(user, branch_name:, message:, actions:, author_email: nil, author_name: nil, start_branch_name: nil, start_sha: nil, start_repository: nil, force: false, sign: true, target_sha: nil) ⇒ Gitlab::Git::OperationService::BranchUpdate
Creates a commit.
- #compare_source_branch(target_branch_name, source_repository, source_branch_name, straight:) ⇒ Object
- #count_commits(options) ⇒ Object
-
#count_commits_between(from, to, options = {}) ⇒ Object
Counts the amount of commits between
fromandto. -
#create_branch(ref, start_point = "HEAD") ⇒ Object
Create a new branch named **ref+ based on **stat_point+, HEAD by default Note: No Git hooks are executed for this action.
- #create_from_bundle(bundle_path) ⇒ Object
- #create_repository(default_branch = nil, object_format: nil) ⇒ Object
- #delete_all_refs_except(prefixes) ⇒ Object
-
#delete_branch(branch_name) ⇒ Object
Delete the specified branch from the repository Note: No Git hooks are executed for this action.
- #delete_refs ⇒ Object
-
#detect_generated_files(base, head, changed_paths) ⇒ Object
rubocop: disable CodeReuse/ActiveRecord – not an active record operation.
-
#diff(from, to, options = {}, *paths) ⇒ Object
Return an array of Diff objects that represent the diff between
fromandto. -
#diff_blobs ⇒ Object
Returns an array of DiffBlob objects that represent a diff between two blobs in a repository.
-
#diff_blobs_with_raw_info ⇒ Object
Returns an array of DiffBlob objects that represent diffs between pairs of blobs in a repository using raw changed path information.
- #diff_stats(left_id, right_id) ⇒ Object
-
#disconnect_alternates ⇒ Object
rubocop:enable Metrics/ParameterLists.
-
#diverging_commit_count(from, to, max_count: 0) ⇒ Object
Return total diverging commits count.
- #empty? ⇒ Boolean
-
#empty_tree_id ⇒ Object
Note: this problem should be addressed in gitlab.com/gitlab-org/gitlab/-/issues/441770 Gitlab::Git::Repository shouldn’t call Repository directly Instead empty_tree_id value should be passed to Gitaly client via method arguments.
- #exists? ⇒ Boolean
- #expire_has_local_branches_cache ⇒ Object
-
#fetch_remote(url, refmap: nil, ssh_auth: nil, forced: false, no_tags: false, prune: true, http_authorization_header: "", resolved_address: "") ⇒ Object
Fetch remote for repository.
- #fetch_source_branch!(source_repository, source_branch, local_ref) ⇒ Object
- #ff_merge(user, source_sha:, target_branch:, target_sha: nil) ⇒ Object
-
#find_branch(name) ⇒ Object
Directly find a branch with a simple name (e.g. master).
- #find_changed_paths(treeish_objects, merge_commit_diff_mode: nil, find_renames: false, diff_filters: nil) ⇒ Object
- #find_commits_by_message(query, ref, path, limit, offset) ⇒ Object
- #find_remote_root_ref(remote_url, authorization = nil) ⇒ Object
- #find_tag(name) ⇒ Object
-
#flipper_id ⇒ Object
Support Feature Flag Repository actor.
- #fsck ⇒ Object
- #get_file_attributes(revision, file_paths, attributes) ⇒ Object
- #get_patch_id(old_revision, new_revision) ⇒ Object
- #gitaly_analysis_client ⇒ Object
- #gitaly_blob_client ⇒ Object
- #gitaly_commit_client ⇒ Object
- #gitaly_conflicts_client(our_commit_oid, their_commit_oid) ⇒ Object
- #gitaly_diff_client ⇒ Object
- #gitaly_operation_client ⇒ Object
- #gitaly_ref_client ⇒ Object
- #gitaly_remote_client ⇒ Object
- #gitaly_repository ⇒ Object
- #gitaly_repository_client ⇒ Object
- #gitattribute(path, name) ⇒ Object
- #has_local_branches? ⇒ Boolean (also: #has_visible_content?)
- #hash ⇒ Object
- #import_repository(url, http_authorization_header: '', mirror: false, resolved_address: '') ⇒ Object
- #info_attributes ⇒ Object
-
#initialize(storage, relative_path, gl_repository, gl_project_path, container: nil) ⇒ Repository
constructor
A new instance of Repository.
- #languages(ref = nil) ⇒ Object
- #last_commit_for_path(sha, path, literal_pathspec: false) ⇒ Object
- #license ⇒ Object
- #list_commits(ref:, query: nil, author: nil, committed_before: nil, committed_after: nil, pagination_params: { page_token: nil, limit: 1000 }) ⇒ Object
- #list_commits_by_ref_name(refs) ⇒ Object
- #list_last_commits_for_tree(sha, path, offset: 0, limit: 25, literal_pathspec: false) ⇒ Object
-
#list_refs ⇒ Object
peel_tags slows down the request by a factor of 3-4.
- #local_branches(sort_by: nil, pagination_params: nil) ⇒ Object
-
#log(options) ⇒ Object
Build an array of commits.
-
#ls_files(ref) ⇒ Object
Returns result like “git ls-files” , recursive and full file path.
- #merge(user, source_sha:, target_branch:, message:, target_sha: nil, sign: true, &block) ⇒ Object
-
#merge_base ⇒ Object
Returns the SHA of the most recent common ancestor of
fromandto. - #merge_to_ref(user, **kwargs) ⇒ Object
- #merged_branch_names(branch_names = [], include_identical: false) ⇒ Object
- #new_blobs(newrevs, dynamic_timeout: nil) ⇒ Object
- #new_commits(newrevs) ⇒ Object
-
#object_directory_size ⇒ Object
Return git object directory size in bytes.
- #object_format ⇒ Object
- #object_pool ⇒ Object
- #praefect_info_client ⇒ Object
-
#raw_changes_between(old_rev, new_rev) ⇒ Object
old_rev and new_rev are commit ID’s the result of this method is an array of Gitlab::Git::RawDiffChange.
- #rebase(user, rebase_id, branch:, branch_sha:, remote_repository:, remote_branch:, push_options: [], &block) ⇒ Object
- #rebase_to_ref(user, source_sha:, target_ref:, first_parent_ref:, expected_old_oid: "") ⇒ Object
-
#recent_objects_size ⇒ Object
Return repository recent objects size in mebibytes.
-
#ref_exists?(ref_name) ⇒ Boolean
Returns true if the given ref name exists.
-
#ref_names ⇒ Object
Returns an Array of branch and tag names.
-
#refs_by_oid(oid:, limit: 0, ref_patterns: nil) ⇒ Object
Returns matching refs for OID.
-
#refs_hash ⇒ Object
Get refs hash which key is the commit id and value is a Gitlab::Git::Tag or Gitlab::Git::Branch Note that both inherit from Gitlab::Git::Ref.
- #remove ⇒ Object
- #replicas ⇒ Object
- #replicate(source_repository, partition_hint: "") ⇒ Object
-
#revert(user:, commit:, branch_name:, message:, start_branch_name:, start_repository:, dry_run: false, target_sha: nil, sign: true) ⇒ Object
rubocop:disable Metrics/ParameterLists – all arguments needed.
- #rm_branch(branch_name, user:, target_sha: nil) ⇒ Object
- #rm_tag(tag_name, user:) ⇒ Object
-
#root_ref(head_only: false) ⇒ Object
Default branch in the repository.
- #search_files_by_content(query, ref, options = {}) ⇒ Object
- #search_files_by_name(query, ref, limit: 0, offset: 0) ⇒ Object
- #search_files_by_regexp(filter, ref = 'HEAD', limit: 0, offset: 0) ⇒ Object
-
#size ⇒ Object
Return repo size in megabytes.
- #squash(user, start_sha:, end_sha:, author:, message:, sign: true) ⇒ Object
-
#submodule_url_for(ref, path) ⇒ Object
Returns url for submodule.
-
#submodule_urls_for(ref) ⇒ Object
Returns path to url mappings for submodules.
-
#tag_count ⇒ Object
Returns the number of valid tags.
-
#tag_exists?(name) ⇒ Boolean
Returns true if the given tag exists.
-
#tag_names ⇒ Object
Returns an Array of tag names.
- #tag_names_contains_sha(sha, limit: 0) ⇒ Object
-
#tags(sort_by: nil, pagination_params: nil) ⇒ Object
Returns an Array of Tags.
- #to_s ⇒ Object
- #update_branch(branch_name, user:, newrev:, oldrev:) ⇒ Object
-
#update_refs(ref_list) ⇒ Object
Update a list of references from X -> Y.
- #update_submodule(user:, submodule:, commit_sha:, message:, branch:) ⇒ Object
- #write_ref(ref_path, ref, old_ref: nil) ⇒ Object
Methods included from EncodingHelper
#binary_io, #detect_binary?, #detect_encoding, #detect_libgit2_binary?, #encode!, #encode_binary, #encode_utf8, #encode_utf8_no_detect, #encode_utf8_with_escaping!, #encode_utf8_with_replacement_character, #force_encode_utf8, #strip_bom, #unquote_path
Methods included from WrapsGitalyErrors
Methods included from RepositoryMirroring
Constructor Details
#initialize(storage, relative_path, gl_repository, gl_project_path, container: nil) ⇒ Repository
Returns a new instance of Repository.
72 73 74 75 76 77 78 79 80 |
# File 'lib/gitlab/git/repository.rb', line 72 def initialize(storage, relative_path, gl_repository, gl_project_path, container: nil) @storage = storage @relative_path = relative_path @gl_repository = gl_repository @gl_project_path = gl_project_path @container = container @name = @relative_path.split("/").last end |
Instance Attribute Details
#container ⇒ Object (readonly)
Returns the value of attribute container.
60 61 62 |
# File 'lib/gitlab/git/repository.rb', line 60 def container @container end |
#gl_project_path ⇒ Object (readonly)
Returns the value of attribute gl_project_path.
60 61 62 |
# File 'lib/gitlab/git/repository.rb', line 60 def gl_project_path @gl_project_path end |
#gl_repository ⇒ Object (readonly) Also known as: object_pool_remote_name
Returns the value of attribute gl_repository.
60 61 62 |
# File 'lib/gitlab/git/repository.rb', line 60 def gl_repository @gl_repository end |
#name ⇒ Object (readonly)
Directory name of repo
55 56 57 |
# File 'lib/gitlab/git/repository.rb', line 55 def name @name end |
#relative_path ⇒ Object (readonly)
Relative path of repo
58 59 60 |
# File 'lib/gitlab/git/repository.rb', line 58 def relative_path @relative_path end |
#storage ⇒ Object (readonly)
Returns the value of attribute storage.
60 61 62 |
# File 'lib/gitlab/git/repository.rb', line 60 def storage @storage end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
91 92 93 |
# File 'lib/gitlab/git/repository.rb', line 91 def ==(other) other.is_a?(self.class) && [storage, relative_path] == [other.storage, other.relative_path] end |
#add_branch(branch_name, user:, target:, skip_ci: false) ⇒ Object
653 654 655 656 657 |
# File 'lib/gitlab/git/repository.rb', line 653 def add_branch(branch_name, user:, target:, skip_ci: false) wrapped_gitaly_errors do gitaly_operation_client.user_create_branch(branch_name, user, target, skip_ci: skip_ci) end end |
#add_tag(tag_name, user:, target:, message: nil) ⇒ Object
659 660 661 662 663 |
# File 'lib/gitlab/git/repository.rb', line 659 def add_tag(tag_name, user:, target:, message: nil) wrapped_gitaly_errors do gitaly_operation_client.add_tag(tag_name, user, target, ) end end |
#ancestor?(from, to) ⇒ Boolean
Returns true is from is direct ancestor to to, otherwise false
491 492 493 |
# File 'lib/gitlab/git/repository.rb', line 491 def ancestor?(from, to) gitaly_commit_client.ancestor?(from, to) end |
#archive_metadata(ref, storage_path, project_path, format = "tar.gz", append_sha:, path: nil) ⇒ Object
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/gitlab/git/repository.rb', line 261 def (ref, storage_path, project_path, format = "tar.gz", append_sha:, path: nil) ref ||= root_ref commit_id = extract_commit_id_from_ref(ref) return {} if commit_id.nil? commit = Gitlab::Git::Commit.find(self, commit_id) return {} if commit.nil? prefix = archive_prefix(ref, commit.id, project_path, append_sha: append_sha, path: path) { 'ArchivePrefix' => prefix, 'ArchivePath' => archive_file_path(storage_path, commit.id, prefix, format), 'CommitId' => commit.id, 'GitalyRepository' => gitaly_repository.to_h, 'StoragePath' => storage_path } end |
#async_delete_refs(*refs) ⇒ Object
760 761 762 763 764 765 766 767 768 |
# File 'lib/gitlab/git/repository.rb', line 760 def async_delete_refs(*refs) raise "async_delete_refs only supports project repositories" unless container.is_a?(Project) records = refs.map do |ref| BatchedGitRefUpdates::Deletion.new(project_id: container.id, ref: ref, created_at: Time.current, updated_at: Time.current) end BatchedGitRefUpdates::Deletion.bulk_insert!(records) end |
#attributes(path) ⇒ Object
Returns the Git attributes for the given file path.
See Gitlab::Git::Attributes for more information.
827 828 829 |
# File 'lib/gitlab/git/repository.rb', line 827 def attributes(path) info_attributes.attributes(path) end |
#attributes_at(ref) ⇒ Object
Returns parsed .gitattributes for a given ref
This only parses the root .gitattributes file, it does not traverse subfolders to find additional .gitattributes files
This method is around 30 times slower than attributes, which uses ‘$GIT_DIR/info/attributes`. Consider caching AttributesAtRefParser and reusing that for multiple calls instead of this method.
843 844 845 |
# File 'lib/gitlab/git/repository.rb', line 843 def attributes_at(ref) AttributesAtRefParser.new(self, ref) end |
#batch_blobs(items, blob_size_limit: Gitlab::Git::Blob::MAX_DATA_DISPLAY_SIZE) ⇒ Object
Items should be of format [[commit_id, path], [commit_id1, path1]]
953 954 955 |
# File 'lib/gitlab/git/repository.rb', line 953 def batch_blobs(items, blob_size_limit: Gitlab::Git::Blob::MAX_DATA_DISPLAY_SIZE) Gitlab::Git::Blob.batch(self, items, blob_size_limit: blob_size_limit) end |
#blob_at(sha, path, limit: Gitlab::Git::Blob::MAX_DATA_DISPLAY_SIZE) ⇒ Object
948 949 950 |
# File 'lib/gitlab/git/repository.rb', line 948 def blob_at(sha, path, limit: Gitlab::Git::Blob::MAX_DATA_DISPLAY_SIZE) Gitlab::Git::Blob.find(self, sha, path, limit: limit) unless Gitlab::Git.blank_ref?(sha) end |
#blobs(revisions, with_paths: false, dynamic_timeout: nil) ⇒ Object
List blobs reachable via a set of revisions. Supports the pseudo-revisions --not and --all. Uses the minimum of GitalyClient.medium_timeout and dynamic timeout if the dynamic timeout is set, otherwise it’ll always use the medium timeout.
430 431 432 433 434 435 436 437 438 439 |
# File 'lib/gitlab/git/repository.rb', line 430 def blobs(revisions, with_paths: false, dynamic_timeout: nil) revisions = revisions.reject { |rev| rev.blank? || Gitlab::Git.blank_ref?(rev) } return [] if revisions.blank? wrapped_gitaly_errors do gitaly_blob_client.list_blobs(revisions, limit: REV_LIST_COMMIT_LIMIT, with_paths: with_paths, dynamic_timeout: dynamic_timeout) end end |
#branch_count ⇒ Object
Returns the number of valid branches
168 169 170 |
# File 'lib/gitlab/git/repository.rb', line 168 def branch_count branch_names.count end |
#branch_exists?(name) ⇒ Boolean
Returns true if the given branch exists
name - The name of the branch as a String.
244 245 246 247 248 |
# File 'lib/gitlab/git/repository.rb', line 244 def branch_exists?(name) wrapped_gitaly_errors do gitaly_ref_exists?("refs/heads/#{name}") end end |
#branch_names ⇒ Object
Returns an Array of branch names sorted by name ASC
122 123 124 125 126 |
# File 'lib/gitlab/git/repository.rb', line 122 def branch_names refs = list_refs([Gitlab::Git::BRANCH_REF_PREFIX]) refs.map { |ref| Gitlab::Git.branch_name(ref.name) } end |
#branch_names_contains_sha(sha, limit: 0) ⇒ Object
1100 1101 1102 |
# File 'lib/gitlab/git/repository.rb', line 1100 def branch_names_contains_sha(sha, limit: 0) gitaly_ref_client.branch_names_contains_sha(sha, limit: limit) end |
#branches ⇒ Object
Returns an Array of Branches
129 130 131 132 133 |
# File 'lib/gitlab/git/repository.rb', line 129 def branches wrapped_gitaly_errors do gitaly_ref_client.branches end end |
#bundle_to_disk(save_path) ⇒ Object
1005 1006 1007 1008 1009 1010 1011 |
# File 'lib/gitlab/git/repository.rb', line 1005 def bundle_to_disk(save_path) wrapped_gitaly_errors do gitaly_repository_client.create_bundle(save_path) end true end |
#can_be_merged?(source_sha, target_branch) ⇒ Boolean
1117 1118 1119 1120 1121 1122 1123 |
# File 'lib/gitlab/git/repository.rb', line 1117 def can_be_merged?(source_sha, target_branch) if target_sha = find_branch(target_branch)&.target !gitaly_conflicts_client(source_sha, target_sha).conflicts? else false end end |
#check_objects_exist(refs) ⇒ Object
406 407 408 409 410 |
# File 'lib/gitlab/git/repository.rb', line 406 def check_objects_exist(refs) wrapped_gitaly_errors do gitaly_commit_client.object_existence_map(Array.wrap(refs)) end end |
#checksum ⇒ Object
1192 1193 1194 1195 1196 1197 1198 1199 |
# File 'lib/gitlab/git/repository.rb', line 1192 def checksum # The exists? RPC is much cheaper, so we perform this request first raise NoRepository, "Repository does not exist" unless exists? gitaly_repository_client.calculate_checksum rescue GRPC::NotFound raise NoRepository # Guard against data races. end |
#cherry_pick ⇒ Object
rubocop:enable Metrics/ParameterLists
730 731 732 733 734 |
# File 'lib/gitlab/git/repository.rb', line 730 def cherry_pick(...) wrapped_gitaly_errors do gitaly_operation_client.user_cherry_pick(...) end end |
#clean(options = {}) ⇒ Object
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
645 646 647 648 649 650 651 |
# File 'lib/gitlab/git/repository.rb', line 645 def clean( = {}) strategies = [:remove_untracked] strategies.push(:force) if [:f] strategies.push(:remove_ignored) if [:x] # TODO: implement this method end |
#commit(ref = 'HEAD') ⇒ Object
Refactoring aid; allows us to copy code from app/models/repository.rb
903 904 905 |
# File 'lib/gitlab/git/repository.rb', line 903 def commit(ref = 'HEAD') Gitlab::Git::Commit.find(self, ref) end |
#commit_count(ref) ⇒ Object
Return total commits count accessible from passed ref
616 617 618 619 620 |
# File 'lib/gitlab/git/repository.rb', line 616 def commit_count(ref) wrapped_gitaly_errors do gitaly_commit_client.commit_count(ref) end end |
#commit_files(user, branch_name:, message:, actions:, author_email: nil, author_name: nil, start_branch_name: nil, start_sha: nil, start_repository: nil, force: false, sign: true, target_sha: nil) ⇒ Gitlab::Git::OperationService::BranchUpdate
Creates a commit
rubocop:disable Metrics/ParameterLists
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 |
# File 'lib/gitlab/git/repository.rb', line 1036 def commit_files( user, branch_name:, message:, actions:, author_email: nil, author_name: nil, start_branch_name: nil, start_sha: nil, start_repository: nil, force: false, sign: true, target_sha: nil ) wrapped_gitaly_errors do gitaly_operation_client.user_commit_files(user, branch_name, , actions, , , start_branch_name, start_repository, force, start_sha, sign, target_sha) end end |
#compare_source_branch(target_branch_name, source_repository, source_branch_name, straight:) ⇒ Object
876 877 878 879 880 881 882 883 884 885 |
# File 'lib/gitlab/git/repository.rb', line 876 def compare_source_branch(target_branch_name, source_repository, source_branch_name, straight:) CrossRepo.new(source_repository, self).execute(target_branch_name) do |target_commit_id| Gitlab::Git::Compare.new( source_repository, target_commit_id, source_branch_name, straight: straight ) end end |
#count_commits(options) ⇒ Object
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 |
# File 'lib/gitlab/git/repository.rb', line 441 def count_commits() = (.dup) wrapped_gitaly_errors do if [:left_right] from = [:from] to = [:to] right_count = gitaly_commit_client .commit_count("#{from}..#{to}", ) left_count = gitaly_commit_client .commit_count("#{to}..#{from}", ) [left_count, right_count] else gitaly_commit_client.commit_count([:ref], ) end end end |
#count_commits_between(from, to, options = {}) ⇒ Object
Counts the amount of commits between from and to.
462 463 464 |
# File 'lib/gitlab/git/repository.rb', line 462 def count_commits_between(from, to, = {}) count_commits(from: from, to: to, **) end |
#create_branch(ref, start_point = "HEAD") ⇒ Object
Create a new branch named **ref+ based on **stat_point+, HEAD by default Note: No Git hooks are executed for this action
Examples:
create_branch("feature")
create_branch("other-feature", "master")
796 797 798 |
# File 'lib/gitlab/git/repository.rb', line 796 def create_branch(ref, start_point = "HEAD") write_ref(ref, start_point) end |
#create_from_bundle(bundle_path) ⇒ Object
963 964 965 966 967 968 969 970 |
# File 'lib/gitlab/git/repository.rb', line 963 def create_from_bundle(bundle_path) # It's important to check that the linked-to file is actually a valid # .bundle file as it is passed to `git clone`, which may otherwise # interpret it as a pointer to another repository ::Gitlab::Git::BundleFile.check!(bundle_path) gitaly_repository_client.create_from_bundle(bundle_path) end |
#create_repository(default_branch = nil, object_format: nil) ⇒ Object
112 113 114 115 116 117 118 |
# File 'lib/gitlab/git/repository.rb', line 112 def create_repository(default_branch = nil, object_format: nil) wrapped_gitaly_errors do gitaly_repository_client.create_repository(default_branch, object_format: object_format) rescue GRPC::AlreadyExists => e raise RepositoryExists, e. end end |
#delete_all_refs_except(prefixes) ⇒ Object
255 256 257 258 259 |
# File 'lib/gitlab/git/repository.rb', line 255 def delete_all_refs_except(prefixes) wrapped_gitaly_errors do gitaly_ref_client.delete_refs(except_with_prefixes: prefixes) end end |
#delete_branch(branch_name) ⇒ Object
Delete the specified branch from the repository Note: No Git hooks are executed for this action
752 753 754 755 756 757 758 |
# File 'lib/gitlab/git/repository.rb', line 752 def delete_branch(branch_name) branch_name = "#{Gitlab::Git::BRANCH_REF_PREFIX}#{branch_name}" unless branch_name.start_with?("refs/") delete_refs(branch_name) rescue CommandError => e raise DeleteBranchError, e end |
#delete_refs ⇒ Object
784 785 786 787 788 |
# File 'lib/gitlab/git/repository.rb', line 784 def delete_refs(...) wrapped_gitaly_errors do gitaly_delete_refs(...) end end |
#detect_generated_files(base, head, changed_paths) ⇒ Object
rubocop: disable CodeReuse/ActiveRecord – not an active record operation
1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 |
# File 'lib/gitlab/git/repository.rb', line 1243 def detect_generated_files(base, head, changed_paths) return Set.new if changed_paths.blank? # We only display diffs upto the diff_max_files size so we can avoid # checking the rest if it exceeds the limit. changed_paths = changed_paths.take(Gitlab::CurrentSettings.diff_max_files) # Check .gitattributes overrides first checked_files = get_file_attributes( base, changed_paths.map(&:path), Gitlab::Git::ATTRIBUTE_OVERRIDES[:generated] ).map { |attrs| { path: attrs[:path], generated: attrs[:value] == "set" } } # Check automatic generated file detection for the remaining paths overridden_paths = checked_files.pluck(:path) remainder = changed_paths.reject { |changed_path| overridden_paths.include?(changed_path.path) } checked_files += check_blobs_generated(base, head, remainder) if remainder.present? checked_files .select { |attrs| attrs[:generated] } .pluck(:path) .to_set rescue Gitlab::Git::CommandError, Gitlab::Git::ResourceExhaustedError => e # An exception can be raised due to an unknown revision or paths. # Gitlab::Git::ResourceExhaustedError could be raised if the request payload is too large. Gitlab::ErrorTracking.track_exception( e, gl_project_path: @gl_project_path, base: base, head: head, paths_count: changed_paths.count, paths_bytesize: changed_paths.map(&:path).join.bytesize ) Set.new end |
#diff(from, to, options = {}, *paths) ⇒ Object
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.
531 532 533 534 535 |
# File 'lib/gitlab/git/repository.rb', line 531 def diff(from, to, = {}, *paths) iterator = gitaly_commit_client.diff(from, to, .merge(paths: paths)) Gitlab::Git::DiffCollection.new(iterator, ) end |
#diff_blobs ⇒ Object
Returns an array of DiffBlob objects that represent a diff between two blobs in a repository. For each diff generated, the pre-image and post-image blob IDs should be obtained using find_changed_paths method.
512 513 514 515 516 |
# File 'lib/gitlab/git/repository.rb', line 512 def diff_blobs(...) wrapped_gitaly_errors do gitaly_diff_client.diff_blobs(...) end end |
#diff_blobs_with_raw_info ⇒ Object
Returns an array of DiffBlob objects that represent diffs between pairs of blobs in a repository using raw changed path information. More efficient for large batches of files compared to diff_blobs.
521 522 523 524 525 |
# File 'lib/gitlab/git/repository.rb', line 521 def diff_blobs_with_raw_info(...) wrapped_gitaly_errors do gitaly_diff_client.diff_blobs_with_raw_info(...) end end |
#diff_stats(left_id, right_id) ⇒ Object
537 538 539 540 541 542 543 544 545 546 547 548 549 |
# File 'lib/gitlab/git/repository.rb', line 537 def diff_stats(left_id, right_id) if [left_id, right_id].any? { |ref| ref.blank? || Gitlab::Git.blank_ref?(ref) } return empty_diff_stats end stats = wrapped_gitaly_errors do gitaly_commit_client.diff_stats(left_id, right_id) end Gitlab::Git::DiffStatsCollection.new(stats) rescue CommandError, TypeError empty_diff_stats end |
#disconnect_alternates ⇒ Object
rubocop:enable Metrics/ParameterLists
1050 1051 1052 1053 1054 |
# File 'lib/gitlab/git/repository.rb', line 1050 def disconnect_alternates wrapped_gitaly_errors do gitaly_repository_client.disconnect_alternates end end |
#diverging_commit_count(from, to, max_count: 0) ⇒ Object
Return total diverging commits count
623 624 625 626 627 |
# File 'lib/gitlab/git/repository.rb', line 623 def diverging_commit_count(from, to, max_count: 0) wrapped_gitaly_errors do gitaly_commit_client.diverging_commit_count(from, to, max_count: max_count) end end |
#empty? ⇒ Boolean
907 908 909 |
# File 'lib/gitlab/git/repository.rb', line 907 def empty? !has_visible_content? end |
#empty_tree_id ⇒ Object
Note: this problem should be addressed in gitlab.com/gitlab-org/gitlab/-/issues/441770 Gitlab::Git::Repository shouldn’t call Repository directly Instead empty_tree_id value should be passed to Gitaly client via method arguments
1223 1224 1225 |
# File 'lib/gitlab/git/repository.rb', line 1223 def empty_tree_id container.repository.empty_tree_id end |
#exists? ⇒ Boolean
108 109 110 |
# File 'lib/gitlab/git/repository.rb', line 108 def exists? gitaly_repository_client.exists? end |
#expire_has_local_branches_cache ⇒ Object
186 187 188 |
# File 'lib/gitlab/git/repository.rb', line 186 def expire_has_local_branches_cache clear_memoization(:has_local_branches) end |
#fetch_remote(url, refmap: nil, ssh_auth: nil, forced: false, no_tags: false, prune: true, http_authorization_header: "", resolved_address: "") ⇒ Object
Fetch remote for repository
remote - remote name url - URL of the remote to fetch. remote is not used in this case. refmap - if url is given, determines which references should get fetched where ssh_auth - SSH known_hosts data and a private key to use for public-key authentication forced - should we use –force flag? no_tags - should we use –no-tags flag? prune - should we use –prune flag? resolved_address - resolved IP address for provided URL
921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 |
# File 'lib/gitlab/git/repository.rb', line 921 def fetch_remote( url, refmap: nil, ssh_auth: nil, forced: false, no_tags: false, prune: true, http_authorization_header: "", resolved_address: "") wrapped_gitaly_errors do gitaly_repository_client.fetch_remote( url, refmap: refmap, ssh_auth: ssh_auth, forced: forced, no_tags: , prune: prune, timeout: GITLAB_PROJECTS_TIMEOUT, http_authorization_header: , resolved_address: resolved_address ) end end |
#fetch_source_branch!(source_repository, source_branch, local_ref) ⇒ Object
870 871 872 873 874 |
# File 'lib/gitlab/git/repository.rb', line 870 def fetch_source_branch!(source_repository, source_branch, local_ref) wrapped_gitaly_errors do gitaly_repository_client.fetch_source_branch(source_repository, source_branch, local_ref) end end |
#ff_merge(user, source_sha:, target_branch:, target_sha: nil) ⇒ Object
701 702 703 704 705 706 707 708 |
# File 'lib/gitlab/git/repository.rb', line 701 def ff_merge(user, source_sha:, target_branch:, target_sha: nil) wrapped_gitaly_errors do gitaly_operation_client.user_ff_branch(user, source_sha: source_sha, target_branch: target_branch, target_sha: target_sha) end end |
#find_branch(name) ⇒ Object
Directly find a branch with a simple name (e.g. master)
137 138 139 140 141 142 143 144 145 |
# File 'lib/gitlab/git/repository.rb', line 137 def find_branch(name) wrapped_gitaly_errors do gitaly_ref_client.find_branch(name) end rescue Gitlab::Git::AmbiguousRef # Gitaly returns "reference is ambiguous" error in case when users request # branch "my-branch", when another branch "my-branch/branch" exists. # We handle this error here and return nil for this case. end |
#find_changed_paths(treeish_objects, merge_commit_diff_mode: nil, find_renames: false, diff_filters: nil) ⇒ Object
551 552 553 554 555 556 557 558 559 560 561 |
# File 'lib/gitlab/git/repository.rb', line 551 def find_changed_paths(treeish_objects, merge_commit_diff_mode: nil, find_renames: false, diff_filters: nil) processed_objects = treeish_objects.compact return [] if processed_objects.empty? wrapped_gitaly_errors do gitaly_commit_client.find_changed_paths(processed_objects, merge_commit_diff_mode: merge_commit_diff_mode, find_renames: find_renames, diff_filters: diff_filters) end rescue CommandError, TypeError, NoRepository [] end |
#find_commits_by_message(query, ref, path, limit, offset) ⇒ Object
1144 1145 1146 1147 1148 |
# File 'lib/gitlab/git/repository.rb', line 1144 def (query, ref, path, limit, offset) wrapped_gitaly_errors do gitaly_commit_client.(query, revision: ref, path: path, limit: limit, offset: offset) end end |
#find_remote_root_ref(remote_url, authorization = nil) ⇒ Object
800 801 802 803 804 805 806 |
# File 'lib/gitlab/git/repository.rb', line 800 def find_remote_root_ref(remote_url, = nil) return unless remote_url.present? wrapped_gitaly_errors do gitaly_remote_client.find_remote_root_ref(remote_url, ) end end |
#find_tag(name) ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/gitlab/git/repository.rb', line 147 def find_tag(name) wrapped_gitaly_errors do gitaly_ref_client.find_tag(name) end rescue CommandError # Gitaly used to return an `Internal` error in case the tag wasn't found, which is being translated to # `CommandError` by the wrapper. This has been converted in v15.3.0 to instead return a structured # error with a `tag_not_found` error, so rescuing from `Internal` errors can be removed in v15.4.0 and # later. rescue Gitlab::Git::ReferenceNotFoundError # This is the new error returned by `find_tag`, which knows to translate the structured error returned # by Gitaly when the tag does not exist. end |
#flipper_id ⇒ Object
Support Feature Flag Repository actor
87 88 89 |
# File 'lib/gitlab/git/repository.rb', line 87 def flipper_id "Repository:#{@relative_path}" end |
#fsck ⇒ Object
957 958 959 960 961 |
# File 'lib/gitlab/git/repository.rb', line 957 def fsck msg, status = gitaly_repository_client.fsck raise GitError, "Could not fsck repository: #{msg}" unless status == 0 end |
#get_file_attributes(revision, file_paths, attributes) ⇒ Object
1233 1234 1235 1236 1237 1238 1239 1240 |
# File 'lib/gitlab/git/repository.rb', line 1233 def get_file_attributes(revision, file_paths, attributes) wrapped_gitaly_errors do gitaly_repository_client .get_file_attributes(revision, file_paths, attributes) .attribute_infos .map(&:to_h) end end |
#get_patch_id(old_revision, new_revision) ⇒ Object
1207 1208 1209 1210 1211 |
# File 'lib/gitlab/git/repository.rb', line 1207 def get_patch_id(old_revision, new_revision) wrapped_gitaly_errors do gitaly_commit_client.get_patch_id(old_revision, new_revision) end end |
#gitaly_analysis_client ⇒ Object
1096 1097 1098 |
# File 'lib/gitlab/git/repository.rb', line 1096 def gitaly_analysis_client @gitaly_analysis_client ||= Gitlab::GitalyClient::AnalysisService.new(self) end |
#gitaly_blob_client ⇒ Object
1080 1081 1082 |
# File 'lib/gitlab/git/repository.rb', line 1080 def gitaly_blob_client @gitaly_blob_client ||= Gitlab::GitalyClient::BlobService.new(self) end |
#gitaly_commit_client ⇒ Object
1064 1065 1066 |
# File 'lib/gitlab/git/repository.rb', line 1064 def gitaly_commit_client @gitaly_commit_client ||= Gitlab::GitalyClient::CommitService.new(self) end |
#gitaly_conflicts_client(our_commit_oid, their_commit_oid) ⇒ Object
1088 1089 1090 |
# File 'lib/gitlab/git/repository.rb', line 1088 def gitaly_conflicts_client(our_commit_oid, their_commit_oid) Gitlab::GitalyClient::ConflictsService.new(self, our_commit_oid, their_commit_oid) end |
#gitaly_diff_client ⇒ Object
1084 1085 1086 |
# File 'lib/gitlab/git/repository.rb', line 1084 def gitaly_diff_client @gitaly_diff_client ||= Gitlab::GitalyClient::DiffService.new(self) end |
#gitaly_operation_client ⇒ Object
1072 1073 1074 |
# File 'lib/gitlab/git/repository.rb', line 1072 def gitaly_operation_client @gitaly_operation_client ||= Gitlab::GitalyClient::OperationService.new(self) end |
#gitaly_ref_client ⇒ Object
1060 1061 1062 |
# File 'lib/gitlab/git/repository.rb', line 1060 def gitaly_ref_client @gitaly_ref_client ||= Gitlab::GitalyClient::RefService.new(self) end |
#gitaly_remote_client ⇒ Object
1076 1077 1078 |
# File 'lib/gitlab/git/repository.rb', line 1076 def gitaly_remote_client @gitaly_remote_client ||= Gitlab::GitalyClient::RemoteService.new(self) end |
#gitaly_repository ⇒ Object
1056 1057 1058 |
# File 'lib/gitlab/git/repository.rb', line 1056 def gitaly_repository Gitlab::GitalyClient::Util.repository(@storage, @relative_path, @gl_repository, @gl_project_path) end |
#gitaly_repository_client ⇒ Object
1068 1069 1070 |
# File 'lib/gitlab/git/repository.rb', line 1068 def gitaly_repository_client @gitaly_repository_client ||= Gitlab::GitalyClient::RepositoryService.new(self) end |
#gitattribute(path, name) ⇒ Object
831 832 833 |
# File 'lib/gitlab/git/repository.rb', line 831 def gitattribute(path, name) attributes(path)[name] end |
#has_local_branches? ⇒ Boolean Also known as: has_visible_content?
190 191 192 193 194 |
# File 'lib/gitlab/git/repository.rb', line 190 def has_local_branches? strong_memoize(:has_local_branches) do uncached_has_local_branches? end end |
#hash ⇒ Object
97 98 99 |
# File 'lib/gitlab/git/repository.rb', line 97 def hash [self.class, storage, relative_path].hash end |
#import_repository(url, http_authorization_header: '', mirror: false, resolved_address: '') ⇒ Object
940 941 942 943 944 945 946 |
# File 'lib/gitlab/git/repository.rb', line 940 def import_repository(url, http_authorization_header: '', mirror: false, resolved_address: '') raise ArgumentError, "don't use disk paths with import_repository: #{url.inspect}" if url.start_with?('.', '/') wrapped_gitaly_errors do gitaly_repository_client.import_repository(url, http_authorization_header: , mirror: mirror, resolved_address: resolved_address) end end |
#info_attributes ⇒ Object
817 818 819 820 821 822 |
# File 'lib/gitlab/git/repository.rb', line 817 def info_attributes return @info_attributes if @info_attributes content = gitaly_repository_client.info_attributes @info_attributes = AttributesParser.new(content) end |
#languages(ref = nil) ⇒ Object
847 848 849 850 851 |
# File 'lib/gitlab/git/repository.rb', line 847 def languages(ref = nil) wrapped_gitaly_errors do gitaly_commit_client.languages(ref) end end |
#last_commit_for_path(sha, path, literal_pathspec: false) ⇒ Object
1186 1187 1188 1189 1190 |
# File 'lib/gitlab/git/repository.rb', line 1186 def last_commit_for_path(sha, path, literal_pathspec: false) wrapped_gitaly_errors do gitaly_commit_client.last_commit_for_path(sha, path, literal_pathspec: literal_pathspec) end end |
#license ⇒ Object
853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 |
# File 'lib/gitlab/git/repository.rb', line 853 def license wrapped_gitaly_errors do response = gitaly_repository_client.find_license break nil if response.license_short_name.empty? ::Gitlab::Git::DeclaredLicense.new(key: response.license_short_name, name: response.license_name, nickname: response.license_nickname.presence, url: response.license_url.presence, path: response.license_path) end rescue Licensee::InvalidLicense => e Gitlab::ErrorTracking.track_exception(e) nil end |
#list_commits(ref:, query: nil, author: nil, committed_before: nil, committed_after: nil, pagination_params: { page_token: nil, limit: 1000 }) ⇒ Object
1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 |
# File 'lib/gitlab/git/repository.rb', line 1150 def list_commits( ref:, query: nil, author: nil, committed_before: nil, committed_after: nil, pagination_params: { page_token: nil, limit: 1000 } ) pagination_params[:limit] ||= 1000 wrapped_gitaly_errors do gitaly_commit_client.list_commits( [ref], author: , ignore_case: true, commit_message_patterns: query, before: committed_before, after: committed_after, reverse: false, pagination_params: pagination_params ) end end |
#list_commits_by_ref_name(refs) ⇒ Object
1180 1181 1182 1183 1184 |
# File 'lib/gitlab/git/repository.rb', line 1180 def list_commits_by_ref_name(refs) wrapped_gitaly_errors do gitaly_commit_client.list_commits_by_ref_name(refs) end end |
#list_last_commits_for_tree(sha, path, offset: 0, limit: 25, literal_pathspec: false) ⇒ Object
1174 1175 1176 1177 1178 |
# File 'lib/gitlab/git/repository.rb', line 1174 def list_last_commits_for_tree(sha, path, offset: 0, limit: 25, literal_pathspec: false) wrapped_gitaly_errors do gitaly_commit_client.list_last_commits_for_tree(sha, path, offset: offset, limit: limit, literal_pathspec: literal_pathspec) end end |
#list_refs ⇒ Object
peel_tags slows down the request by a factor of 3-4
896 897 898 899 900 |
# File 'lib/gitlab/git/repository.rb', line 896 def list_refs(...) wrapped_gitaly_errors do gitaly_ref_client.list_refs(...) end end |
#local_branches(sort_by: nil, pagination_params: nil) ⇒ Object
161 162 163 164 165 |
# File 'lib/gitlab/git/repository.rb', line 161 def local_branches(sort_by: nil, pagination_params: nil) wrapped_gitaly_errors do gitaly_ref_client.local_branches(sort_by: sort_by, pagination_params: pagination_params) end end |
#log(options) ⇒ Object
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),
message_regex: 'project'
)
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 |
# File 'lib/gitlab/git/repository.rb', line 380 def log() raise ArgumentError, 'Invalid message_regex pattern' unless ([:message_regex]) = DEFAULT_LOG_OPTIONS.merge() limit = [:limit] if limit == 0 || !limit.is_a?(Integer) raise ArgumentError, "invalid Repository#log limit: #{limit.inspect}" end # call Gitaly client to fetch commits, if a NotFound happens we return an empty array begin wrapped_gitaly_errors do gitaly_commit_client.find_commits() end rescue Gitlab::Git::Repository::CommitNotFound [] end end |
#ls_files(ref) ⇒ Object
Returns result like “git ls-files” , recursive and full file path
Ex.
repo.ls_files('master')
813 814 815 |
# File 'lib/gitlab/git/repository.rb', line 813 def ls_files(ref) gitaly_commit_client.ls_files(ref) end |
#merge(user, source_sha:, target_branch:, message:, target_sha: nil, sign: true, &block) ⇒ Object
689 690 691 692 693 694 695 696 697 698 699 |
# File 'lib/gitlab/git/repository.rb', line 689 def merge(user, source_sha:, target_branch:, message:, target_sha: nil, sign: true, &block) wrapped_gitaly_errors do gitaly_operation_client.user_merge_branch(user, source_sha: source_sha, target_branch: target_branch, message: , target_sha: target_sha, sign: sign, &block) end end |
#merge_base ⇒ Object
Returns the SHA of the most recent common ancestor of from and to
484 485 486 487 488 |
# File 'lib/gitlab/git/repository.rb', line 484 def merge_base(...) wrapped_gitaly_errors do gitaly_repository_client.find_merge_base(...) end end |
#merge_to_ref(user, **kwargs) ⇒ Object
683 684 685 686 687 |
# File 'lib/gitlab/git/repository.rb', line 683 def merge_to_ref(user, **kwargs) wrapped_gitaly_errors do gitaly_operation_client.user_merge_to_ref(user, **kwargs) end end |
#merged_branch_names(branch_names = [], include_identical: false) ⇒ Object
495 496 497 498 499 500 501 502 503 504 505 506 507 |
# File 'lib/gitlab/git/repository.rb', line 495 def merged_branch_names(branch_names = [], include_identical: false) return [] unless root_ref root_branch = find_branch(root_ref) return [] unless root_branch root_sha = root_branch.target root_branch_name = root_branch.name wrapped_gitaly_errors do Set.new(gitaly_merged_branch_names(branch_names, root_sha, root_branch_name, include_identical: include_identical)) end end |
#new_blobs(newrevs, dynamic_timeout: nil) ⇒ Object
412 413 414 415 416 417 418 419 420 421 422 423 424 |
# File 'lib/gitlab/git/repository.rb', line 412 def new_blobs(newrevs, dynamic_timeout: nil) newrevs = Array.wrap(newrevs).reject { |rev| rev.blank? || Gitlab::Git.blank_ref?(rev) } return [] if newrevs.empty? newrevs = newrevs.uniq.sort @new_blobs ||= {} @new_blobs[newrevs] ||= blobs( ['--not', '--all', '--not'] + newrevs, with_paths: true, dynamic_timeout: dynamic_timeout ).to_a end |
#new_commits(newrevs) ⇒ Object
400 401 402 403 404 |
# File 'lib/gitlab/git/repository.rb', line 400 def new_commits(newrevs) wrapped_gitaly_errors do gitaly_commit_client.list_new_commits(Array.wrap(newrevs)) end end |
#object_directory_size ⇒ Object
Return git object directory size in bytes
365 366 367 |
# File 'lib/gitlab/git/repository.rb', line 365 def object_directory_size gitaly_repository_client.get_object_directory_size.to_f * 1024 end |
#object_format ⇒ Object
1227 1228 1229 1230 1231 |
# File 'lib/gitlab/git/repository.rb', line 1227 def object_format wrapped_gitaly_errors do gitaly_repository_client.object_format.format end end |
#object_pool ⇒ Object
1213 1214 1215 1216 1217 |
# File 'lib/gitlab/git/repository.rb', line 1213 def object_pool wrapped_gitaly_errors do gitaly_repository_client.object_pool.object_pool end end |
#praefect_info_client ⇒ Object
1092 1093 1094 |
# File 'lib/gitlab/git/repository.rb', line 1092 def praefect_info_client @praefect_info_client ||= Gitlab::GitalyClient::PraefectInfoService.new(self) end |
#raw_changes_between(old_rev, new_rev) ⇒ Object
old_rev and new_rev are commit ID’s the result of this method is an array of Gitlab::Git::RawDiffChange
468 469 470 471 472 473 474 475 476 477 478 479 480 481 |
# File 'lib/gitlab/git/repository.rb', line 468 def raw_changes_between(old_rev, new_rev) @raw_changes_between ||= {} return [] if new_rev.blank? || Gitlab::Git.blank_ref?(new_rev) @raw_changes_between[[old_rev, new_rev]] ||= wrapped_gitaly_errors do gitaly_repository_client.raw_changes_between(old_rev, new_rev) .each_with_object([]) do |msg, arr| msg.raw_changes.each { |change| arr << ::Gitlab::Git::RawDiffChange.new(change) } end end rescue ArgumentError => e raise Gitlab::Git::Repository::GitError, e end |
#rebase(user, rebase_id, branch:, branch_sha:, remote_repository:, remote_branch:, push_options: [], &block) ⇒ Object
972 973 974 975 976 977 978 979 980 981 982 983 984 985 |
# File 'lib/gitlab/git/repository.rb', line 972 def rebase(user, rebase_id, branch:, branch_sha:, remote_repository:, remote_branch:, push_options: [], &block) wrapped_gitaly_errors do gitaly_operation_client.rebase( user, rebase_id, branch: branch, branch_sha: branch_sha, remote_repository: remote_repository, remote_branch: remote_branch, push_options: , &block ) end end |
#rebase_to_ref(user, source_sha:, target_ref:, first_parent_ref:, expected_old_oid: "") ⇒ Object
987 988 989 990 991 992 993 994 995 996 997 |
# File 'lib/gitlab/git/repository.rb', line 987 def rebase_to_ref(user, source_sha:, target_ref:, first_parent_ref:, expected_old_oid: "") wrapped_gitaly_errors do gitaly_operation_client.user_rebase_to_ref( user, source_sha: source_sha, target_ref: target_ref, first_parent_ref: first_parent_ref, expected_old_oid: expected_old_oid ) end end |
#recent_objects_size ⇒ Object
Return repository recent objects size in mebibytes
This differs from the #size method in that it does not include the size of:
-
stale objects
-
cruft packs of unreachable objects
356 357 358 359 360 361 362 |
# File 'lib/gitlab/git/repository.rb', line 356 def recent_objects_size wrapped_gitaly_errors do recent_size_in_bytes = gitaly_repository_client.repository_info.objects.recent_size Gitlab::Utils.bytes_to_megabytes(recent_size_in_bytes) end end |
#ref_exists?(ref_name) ⇒ Boolean
Returns true if the given ref name exists
Ref names must start with refs/.
226 227 228 229 230 |
# File 'lib/gitlab/git/repository.rb', line 226 def ref_exists?(ref_name) wrapped_gitaly_errors do gitaly_ref_exists?(ref_name) end end |
#ref_names ⇒ Object
Returns an Array of branch and tag names
251 252 253 |
# File 'lib/gitlab/git/repository.rb', line 251 def ref_names branch_names + tag_names end |
#refs_by_oid(oid:, limit: 0, ref_patterns: nil) ⇒ Object
Returns matching refs for OID
Limit of 0 means there is no limit.
583 584 585 586 587 588 589 |
# File 'lib/gitlab/git/repository.rb', line 583 def refs_by_oid(oid:, limit: 0, ref_patterns: nil) wrapped_gitaly_errors do gitaly_ref_client.find_refs_by_oid(oid: oid, limit: limit, ref_patterns: ref_patterns) || [] end rescue CommandError, TypeError, NoRepository [] end |
#refs_hash ⇒ Object
Get refs hash which key is the commit id and value is a Gitlab::Git::Tag or Gitlab::Git::Branch Note that both inherit from Gitlab::Git::Ref
566 567 568 569 570 571 572 573 574 575 576 577 578 |
# File 'lib/gitlab/git/repository.rb', line 566 def refs_hash return @refs_hash if @refs_hash @refs_hash = Hash.new { |h, k| h[k] = [] } ( + branches).each do |ref| next unless ref.target && ref.name && ref.dereferenced_target&.id @refs_hash[ref.dereferenced_target.id] << ref.name end @refs_hash end |
#remove ⇒ Object
172 173 174 175 176 177 178 |
# File 'lib/gitlab/git/repository.rb', line 172 def remove wrapped_gitaly_errors do gitaly_repository_client.remove end rescue NoRepository nil end |
#replicas ⇒ Object
1201 1202 1203 1204 1205 |
# File 'lib/gitlab/git/repository.rb', line 1201 def replicas wrapped_gitaly_errors do praefect_info_client.replicas end end |
#replicate(source_repository, partition_hint: "") ⇒ Object
180 181 182 183 184 |
# File 'lib/gitlab/git/repository.rb', line 180 def replicate(source_repository, partition_hint: "") wrapped_gitaly_errors do gitaly_repository_client.replicate(source_repository, partition_hint: partition_hint) end end |
#revert(user:, commit:, branch_name:, message:, start_branch_name:, start_repository:, dry_run: false, target_sha: nil, sign: true) ⇒ Object
rubocop:disable Metrics/ParameterLists – all arguments needed
711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 |
# File 'lib/gitlab/git/repository.rb', line 711 def revert(user:, commit:, branch_name:, message:, start_branch_name:, start_repository:, dry_run: false, target_sha: nil, sign: true) args = { user: user, commit: commit, branch_name: branch_name, message: , start_branch_name: start_branch_name, start_repository: start_repository, dry_run: dry_run, target_sha: target_sha, sign: sign } wrapped_gitaly_errors do gitaly_operation_client.user_revert(**args) end end |
#rm_branch(branch_name, user:, target_sha: nil) ⇒ Object
671 672 673 674 675 |
# File 'lib/gitlab/git/repository.rb', line 671 def rm_branch(branch_name, user:, target_sha: nil) wrapped_gitaly_errors do gitaly_operation_client.user_delete_branch(branch_name, user, target_sha: target_sha) end end |
#rm_tag(tag_name, user:) ⇒ Object
677 678 679 680 681 |
# File 'lib/gitlab/git/repository.rb', line 677 def rm_tag(tag_name, user:) wrapped_gitaly_errors do gitaly_operation_client.rm_tag(tag_name, user) end end |
#root_ref(head_only: false) ⇒ Object
Default branch in the repository
102 103 104 105 106 |
# File 'lib/gitlab/git/repository.rb', line 102 def root_ref(head_only: false) wrapped_gitaly_errors do gitaly_ref_client.default_branch_name(head_only: head_only) end end |
#search_files_by_content(query, ref, options = {}) ⇒ Object
1108 1109 1110 1111 1112 1113 1114 1115 |
# File 'lib/gitlab/git/repository.rb', line 1108 def search_files_by_content(query, ref, = {}) return [] if empty? || query.blank? safe_query = Regexp.escape(query) ref ||= root_ref gitaly_repository_client.search_files_by_content(ref, safe_query, ) end |
#search_files_by_name(query, ref, limit: 0, offset: 0) ⇒ Object
1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 |
# File 'lib/gitlab/git/repository.rb', line 1125 def search_files_by_name(query, ref, limit: 0, offset: 0) safe_query = query.sub(%r{^/*}, "") ref ||= root_ref return [] if empty? || safe_query.blank? gitaly_repository_client.search_files_by_name(ref, safe_query, limit: limit, offset: offset).map do |file| Gitlab::EncodingHelper.encode_utf8(file) end end |
#search_files_by_regexp(filter, ref = 'HEAD', limit: 0, offset: 0) ⇒ Object
1136 1137 1138 1139 1140 1141 1142 |
# File 'lib/gitlab/git/repository.rb', line 1136 def search_files_by_regexp(filter, ref = 'HEAD', limit: 0, offset: 0) gitaly_repository_client.search_files_by_regexp(ref, filter, limit: limit, offset: offset).map do |file| Gitlab::EncodingHelper.encode_utf8(file) end rescue GRPC::NotFound raise NoRepository end |
#size ⇒ Object
Return repo size in megabytes
340 341 342 343 344 345 346 347 |
# File 'lib/gitlab/git/repository.rb', line 340 def size if Feature.enabled?(:use_repository_info_for_repository_size) repository_info_size_megabytes else kilobytes = gitaly_repository_client.repository_size (kilobytes.to_f / 1024).round(2) end end |
#squash(user, start_sha:, end_sha:, author:, message:, sign: true) ⇒ Object
999 1000 1001 1002 1003 |
# File 'lib/gitlab/git/repository.rb', line 999 def squash(user, start_sha:, end_sha:, author:, message:, sign: true) wrapped_gitaly_errors do gitaly_operation_client.user_squash(user, start_sha: start_sha, end_sha: end_sha, author: , message: , sign: sign) end end |
#submodule_url_for(ref, path) ⇒ Object
Returns url for submodule
Ex.
@repository.submodule_url_for('master', 'rack')
# => git@localhost:rack.git
597 598 599 600 601 |
# File 'lib/gitlab/git/repository.rb', line 597 def submodule_url_for(ref, path) wrapped_gitaly_errors do gitaly_submodule_url_for(ref, path) end end |
#submodule_urls_for(ref) ⇒ Object
Returns path to url mappings for submodules
Ex.
@repository.submodule_urls_for('master')
# => { 'rack' => 'git@localhost:rack.git' }
609 610 611 612 613 |
# File 'lib/gitlab/git/repository.rb', line 609 def submodule_urls_for(ref) wrapped_gitaly_errors do gitaly_submodule_urls_for(ref) end end |
#tag_count ⇒ Object
Returns the number of valid tags
204 205 206 |
# File 'lib/gitlab/git/repository.rb', line 204 def tag_count tag_names.count end |
#tag_exists?(name) ⇒ Boolean
Returns true if the given tag exists
name - The name of the tag as a String.
235 236 237 238 239 |
# File 'lib/gitlab/git/repository.rb', line 235 def tag_exists?(name) wrapped_gitaly_errors do gitaly_ref_exists?("refs/tags/#{name}") end end |
#tag_names ⇒ Object
Returns an Array of tag names
209 210 211 212 213 |
# File 'lib/gitlab/git/repository.rb', line 209 def tag_names refs = list_refs([Gitlab::Git::TAG_REF_PREFIX]) refs.map { |ref| Gitlab::Git.tag_name(ref.name) } end |
#tag_names_contains_sha(sha, limit: 0) ⇒ Object
1104 1105 1106 |
# File 'lib/gitlab/git/repository.rb', line 1104 def tag_names_contains_sha(sha, limit: 0) gitaly_ref_client.tag_names_contains_sha(sha, limit: limit) end |
#tags(sort_by: nil, pagination_params: nil) ⇒ Object
Returns an Array of Tags
217 218 219 220 221 |
# File 'lib/gitlab/git/repository.rb', line 217 def (sort_by: nil, pagination_params: nil) wrapped_gitaly_errors do gitaly_ref_client.(sort_by: sort_by, pagination_params: pagination_params) end end |
#to_s ⇒ Object
82 83 84 |
# File 'lib/gitlab/git/repository.rb', line 82 def to_s "<#{self.class.name}: #{self.gl_project_path}>" end |
#update_branch(branch_name, user:, newrev:, oldrev:) ⇒ Object
665 666 667 668 669 |
# File 'lib/gitlab/git/repository.rb', line 665 def update_branch(branch_name, user:, newrev:, oldrev:) wrapped_gitaly_errors do gitaly_operation_client.user_update_branch(branch_name, user, newrev, oldrev) end end |
#update_refs(ref_list) ⇒ Object
Update a list of references from X -> Y
Ref list is expected to be an array of hashes in the form: old_sha: new_sha reference:
When new_sha is Gitlab::Git::SHA1_BLANK_SHA, then this will be deleted
778 779 780 781 782 |
# File 'lib/gitlab/git/repository.rb', line 778 def update_refs(ref_list) wrapped_gitaly_errors do gitaly_ref_client.update_refs(ref_list: ref_list) if ref_list.any? end end |
#update_submodule(user:, submodule:, commit_sha:, message:, branch:) ⇒ Object
736 737 738 739 740 741 742 743 744 745 746 747 748 |
# File 'lib/gitlab/git/repository.rb', line 736 def update_submodule(user:, submodule:, commit_sha:, message:, branch:) args = { user: user, submodule: submodule, commit_sha: commit_sha, branch: branch, message: } wrapped_gitaly_errors do gitaly_operation_client.user_update_submodule(**args) end end |
#write_ref(ref_path, ref, old_ref: nil) ⇒ Object
887 888 889 890 891 892 893 |
# File 'lib/gitlab/git/repository.rb', line 887 def write_ref(ref_path, ref, old_ref: nil) ref_path = "#{Gitlab::Git::BRANCH_REF_PREFIX}#{ref_path}" unless ref_path.start_with?("refs/") || ref_path == "HEAD" wrapped_gitaly_errors do gitaly_repository_client.write_ref(ref_path, ref, old_ref) end end |