module Hub::Context
Methods for inspecting the environment, such as reading git config, repository info, and other.
Constants
- NULL
- PWD
Private Instance Methods
current_dir()
click to toggle source
# File lib/hub/context.rb, line 487 def current_dir PWD end
git_alias_for(name)
click to toggle source
# File lib/hub/context.rb, line 477 def git_alias_for(name) git_config "alias.#{name}" end
git_commentchar()
click to toggle source
# File lib/hub/context.rb, line 507 def git_commentchar if str = git_config('core.commentchar') then str[0,1] else '#' end end
git_editor()
click to toggle source
# File lib/hub/context.rb, line 495 def git_editor # possible: ~/bin/vi, $SOME_ENVIRONMENT_VARIABLE, "C:\Program Files\Vim\gvim.exe" --nofork editor = git_command 'var GIT_EDITOR' editor.gsub!(/\$(\w+|\{\w+\})/) { ENV[$1.tr('{}', '')] } editor = ENV[$1] if editor =~ /^\$(\w+)$/ editor = File.expand_path editor if (editor =~ /^[~.]/ or editor.index('/')) and editor !~ /["']/ # avoid shellsplitting "C:\Program Files" if File.exist? editor then [editor] else editor.shellsplit end end
git_reader()
click to toggle source
# File lib/hub/context.rb, line 92 def git_reader @git_reader ||= GitReader.new ENV['GIT'] end
git_url(owner = nil, name = nil, options = {})
click to toggle source
# File lib/hub/context.rb, line 459 def git_url(owner = nil, name = nil, options = {}) project = github_project(name, owner) project.git_url({:https => https_protocol?}.update(options)) end
github_project(name, owner = nil)
click to toggle source
helper methods for local repo, GH projects
# File lib/hub/context.rb, line 439 def github_project(name, owner = nil) if owner and owner.index('/') owner, name = owner.split('/', 2) elsif name and name.index('/') owner, name = name.split('/', 2) else name ||= repo_name owner ||= github_user end if local_repo(false) and main_project = local_repo.main_project project = main_project.dup project.owner = owner project.name = name project else GithubProject.new(local_repo(false), owner, name) end end
http_clone?()
click to toggle source
legacy setting
# File lib/hub/context.rb, line 469 def http_clone? git_config('--bool hub.http-clone') == 'true' end
https_protocol?()
click to toggle source
# File lib/hub/context.rb, line 473 def https_protocol? git_config('hub.protocol') == 'https' or http_clone? end
is_repo?()
click to toggle source
# File lib/hub/context.rb, line 491 def is_repo? !!local_repo(false) end
local_repo(fatal = true)
click to toggle source
# File lib/hub/context.rb, line 99 def local_repo(fatal = true) return nil if defined?(@local_repo) && @local_repo == false @local_repo = if git_dir = git_command('rev-parse -q --git-dir') LocalRepo.new(git_reader, current_dir, git_dir) elsif fatal raise FatalError, "Not a git repository" else false end end
master_branch()
click to toggle source
# File lib/hub/context.rb, line 121 def master_branch if local_repo(false) local_repo.master_branch else # FIXME: duplicates functionality of LocalRepo#master_branch Branch.new nil, 'refs/heads/master' end end
resolve_github_url(url)
click to toggle source
# File lib/hub/context.rb, line 464 def resolve_github_url(url) GithubURL.resolve(url, local_repo) if url =~ /^https?:/ end
rev_list(a, b)
click to toggle source
# File lib/hub/context.rb, line 481 def rev_list(a, b) git_command("rev-list --cherry-pick --right-only --no-merges #{a}...#{b}") end