Permalink
Browse files

fix prompting for GitHub username in `create` command

Fixes #177
  • Loading branch information...
1 parent 501dbba commit 12a619655262dfb9bf74460bdb0219ece301cf1d @mislav mislav committed May 7, 2012
Showing with 20 additions and 21 deletions.
  1. +1 −0 HISTORY.md
  2. +1 −1 features/clone.feature
  3. +2 −2 features/steps.rb
  4. +8 −13 lib/hub/commands.rb
  5. +8 −5 lib/hub/context.rb
View
@@ -1,5 +1,6 @@
## master
+* fix GitHub username prompt in `create` command
* make `fetch` command work with private repos too
* add `merge` command to merge pull requests
View
@@ -58,7 +58,7 @@ Feature: hub clone
Scenario: Preview cloning a private repo
When I successfully run `hub --noop clone -p rtomayko/ronn`
Then the output should contain exactly "git clone git@github.com:rtomayko/ronn.git\n"
- But nothing should be run
+ But "git clone" should not be run
Scenario: Clone a private repo
When I successfully run `hub clone -p rtomayko/ronn`
View
@@ -74,8 +74,8 @@
step %("git clone #{repo}" should be run)
end
-Then /^nothing should be run$/ do
- history.should be_empty
+Then /^"([^"]+)" should not be run$/ do |pattern|
+ history.all? {|h| h.should_not include(pattern) }
end
Then /^there should be no output$/ do
View
@@ -213,12 +213,10 @@ def clone(args)
# $ hub clone rtomayko/tilt
# $ hub clone tilt
if arg =~ NAME_WITH_OWNER_RE and !File.directory?(arg)
- # FIXME: this logic shouldn't be duplicated here!
name, owner = arg, nil
owner, name = name.split('/', 2) if name.index('/')
- host = ENV['GITHUB_HOST'] || 'github.com'
- project = Context::GithubProject.new(nil, owner || github_user(host), name, host)
- ssh ||= args[0] != 'submodule' && project.owner == github_user(host) || host != 'github.com'
+ project = github_project(name, owner || github_user)
+ ssh ||= args[0] != 'submodule' && project.owner == github_user(project.host) { }
args[idx] = project.git_url(:private => ssh, :https => https_protocol?)
end
break
@@ -452,10 +450,7 @@ def am(args)
# > git remote add origin git@github.com:USER/REPO.git
def init(args)
if args.delete('-g')
- # can't use default_host because there is no local_repo yet
- # FIXME: this shouldn't be here!
- host = ENV['GITHUB_HOST'] || 'github.com'
- project = Context::GithubProject.new(nil, github_user(host), File.basename(current_dir), host)
+ project = github_project(File.basename(current_dir))
url = project.git_url(:private => true, :https => https_protocol?)
args.after ['remote', 'add', 'origin', url]
end
@@ -495,7 +490,8 @@ def fork(args)
def create(args)
if !is_repo?
abort "'create' must be run from inside a git repository"
- elsif owner = github_user
+ else
+ owner = github_user
args.shift
options = {}
options[:private] = true if args.delete('-p')
@@ -731,10 +727,9 @@ def api_client
end
end
- def github_user host = nil
- host ||= local_repo(false) && local_repo.main_host
- return nil if host.nil?
- api_client.config.username(host) { }
+ def github_user host = nil, &block
+ host ||= (local_repo(false) || Context::LocalRepo).default_host
+ api_client.config.username(host, &block)
end
def custom_command? cmd
View
@@ -179,14 +179,17 @@ def known_hosts
git_config('hub.host', :all).to_s.split("\n") + [default_host]
end
- def default_host
+ def self.default_host
ENV['GITHUB_HOST'] || main_host
end
- def main_host
+ def self.main_host
'github.com'
end
+ extend Forwardable
+ def_delegators :'self.class', :default_host, :main_host
+
def ssh_config
@ssh_config ||= SshConfig.new
end
@@ -204,12 +207,12 @@ def self.from_url(url, local_repo)
def initialize(*args)
super
- self.host ||= local_repo.default_host
+ self.host ||= (local_repo || LocalRepo).default_host
end
def private?
repo_data ? repo_data.fetch('private') :
- local_repo && host != local_repo.main_host
+ host != (local_repo || LocalRepo).main_host
end
def owned_by(new_owner)
@@ -360,7 +363,7 @@ def github_project(name, owner = nil)
project.name = name
project
else
- GithubProject.new(local_repo, owner, name)
+ GithubProject.new(local_repo(false), owner, name)
end
end

0 comments on commit 12a6196

Please sign in to comment.