module Git::Helpers
Provides a set of helper functions to make Git
life easier
Provides a set of helper functions to make Git
life easier
Provides a set of helper functions to make Git
life easier
Provides a set of helper functions to make Git
life easier
Provides a set of helper functions to make Git
life easier
Constants
- VERSION
Public Class Methods
Opens the default web browser to the specified repositorys page based on
the the specified remote, and tree
@param repo_dir [String] Directory of the git repo to browse, defaults to current working dir @param remote_name [String] Name of the remote to browse, defaults to origin @param tree [String] Tree to browse, can be a branch name, tag, or commit hash
# File lib/git/helpers/browse.rb, line 13 def self.browse(repo_dir = Dir.pwd, remote_name = 'origin', tree = nil) repo = Git.open(repo_dir) raise "#{remote_name} is not a known remote" unless Utils.remote? repo, remote_name remote = Utils.remotes_hash(repo)[remote_name] tree ||= repo.current_branch url = remote.url.chomp('.git') url = Utils.transform_url(url) url << "/tree/#{tree}" Launchy.open url end
Updates a repositories current branch from upstream, and pushes those
to origin
@param upstream_user [String] The user of the upstream repo @param repo_dir [String] The directory of the repo to update @param print_details [Boolean] Print messages for each action or not
# File lib/git/helpers/create_upstream.rb, line 12 def self.create_upstream(upstream_user, repo_dir = Dir.pwd, print_details = true) repo = Git.open(repo_dir) if Utils.remote?(repo, 'upstream') current = Utils.remotes_hash(repo)['upstream'] puts "Upstream already exists with url: #{current.url}" if print_details return end remote = Utils.remotes_hash(repo)['origin'] user = Utils.true_name(remote) url = Utils.transform_url(remote.url, 'git') url.sub!(user, upstream_user) puts "Adding upstream with URL #{url}" if print_details repo.add_remote('upstream', url) end
Opens the default web browser to an comparison page to open a pull request @param repo_dir [String] Directory of the git repo to browse, defaults to current working dir @param target_remote [String] Name of the target remote, default upstream @param target_branch [String] Name of the branch on the target remote to compare, defaults to current branch @param source_remote [String] Name of the source remote, default origin @param source_branch [String] Name of the branch on the source remote to compare, defaults to current branch
# File lib/git/helpers/pull_request.rb, line 14 def self.pull_request(repo_dir = Dir.pwd, target = 'upstream', target_branch = nil, source = 'origin', source_branch = nil) repo = Git.open(repo_dir) raise "#{target} is not a known remote" unless Utils.remote? repo, target raise "#{source} is not a known remote" unless Utils.remote? repo, source target_remote = Utils.remotes_hash(repo)[target] source_remote = Utils.remotes_hash(repo)[source] target_branch ||= repo.current_branch source_branch ||= repo.current_branch url = target_remote.url.chomp('.git') url = Utils.transform_url(url) url << "/compare/#{target_branch}...#{Utils.true_name(source_remote)}:#{source_branch}?expand=1" Launchy.open url end
Updates a repositories current branch from upstream, and pushes those
to origin
@param repo_dir [String] The directory of the repo to update @param print_details [Boolean] Print messages for each action or not
# File lib/git/helpers/update.rb, line 11 def self.update_repository(repo_dir = Dir.pwd, print_details = true) repo = Git.open(repo_dir) remote = Utils.remote?(repo, 'upstream') ? 'upstream' : 'origin' current_branch = repo.current_branch print "Pulling changes from #{remote}/#{current_branch}..." if print_details repo.pull(remote, current_branch) puts "\tSUCCESS" if print_details if remote != 'origin' print "Pushing changes to origin/#{current_branch}..." if print_details repo.push('origin', current_branch) puts "\tSUCCESS" if print_details end end