lib/gitlab_git/repository.rb in gitlab_git-7.2.19 vs lib/gitlab_git/repository.rb in gitlab_git-7.2.20

- old
+ new

@@ -455,11 +455,12 @@ # Return total commits count accessible from passed ref def commit_count(ref) walker = Rugged::Walker.new(rugged) walker.sorting(Rugged::SORT_TOPO | Rugged::SORT_REVERSE) - walker.push(ref) + oid = rugged.rev_parse_oid(ref) + walker.push(oid) walker.count end # 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: @@ -643,19 +644,56 @@ def checkout(ref, options = {}, start_point = "HEAD") if options[:b] rugged.branches.create(ref, start_point) options.delete(:b) end - default_options = { strategy: :safe_create } + default_options = { strategy: [:recreate_missing, :safe] } rugged.checkout(ref, default_options.merge(options)) end # Delete the specified branch from the repository def delete_branch(branch_name) rugged.branches.delete(branch_name) end + # Create a new branch named **ref+ based on **stat_point+, HEAD by default + # + # Examples: + # create_branch("feature") + # create_branch("other-feature", "master") + def create_branch(ref, start_point = "HEAD") + rugged_ref = rugged.branches.create(ref, start_point) + Branch.new(rugged_ref.name, rugged_ref.target) + rescue Rugged::ReferenceError => e + raise InvalidRef.new("Branch #{ref} already exists") if e.to_s =~ /'refs\/heads\/#{ref}'/ + raise InvalidRef.new("Invalid reference #{start_point}") + end + + # Add a tag with +tag_name++ name to the repository in corresponding +ref_target++ + # supports passing a hash of options to create an annotated tag + # + # Valid annotation options are: + # :tagger :: + # same structure as a committer, the user that is creating the tag + # + # :message :: + # the message to include in the tag annotation + # + # Returns a Gitlab::Git::Tag + def add_tag(tag_name, ref_target, options = nil) + tag = rugged.tags.create(tag_name, ref_target, options) + if tag.annotated? + Tag.new(tag_name, ref_target, tag.annotation.message) + else + Tag.new(tag_name, ref_target) + end + rescue Rugged::TagError + raise InvalidRef.new("Tag #{tag_name} already exists") + rescue Rugged::ReferenceError + raise InvalidRef.new("Target #{ref_target} is invalid") + end + # Return an array of this repository's remote names def remote_names rugged.remotes.each_name.to_a end @@ -673,12 +711,10 @@ # # Example # repo.update_remote("origin", url: "path/to/repo") def remote_update(remote_name, options = {}) # TODO: Implement other remote options - remote = rugged.remotes[remote_name] - remote.url = options[:url] if options[:url] - remote.save + rugged.remotes.set_url(remote_name, options[:url]) if options[:url] end # Fetch the specified remote def fetch(remote_name) rugged.remotes[remote_name].fetch