Skip to content

Commit

Permalink
runner shouldn't think that all ruby methods are git commands
Browse files Browse the repository at this point in the history
closes #64
  • Loading branch information
mislav committed Dec 28, 2010
1 parent c2e575f commit af277fd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/hub/args.rb
Expand Up @@ -13,6 +13,7 @@ def initialize(*args)
@executable = ENV["GIT"] || "git"
@after = nil
@skip = false
@original_args = args.first
end

# With no arguments, returns the `after` callback.
Expand Down Expand Up @@ -74,5 +75,10 @@ def words
def flags
self - words
end

# Tests if arguments were modified since instantiation
def changed?
self != @original_args
end
end
end
2 changes: 1 addition & 1 deletion lib/hub/runner.rb
Expand Up @@ -15,7 +15,7 @@ def initialize(*args)

# git commands can have dashes
cmd = @args[0].sub(/(\w)-/, '\1_')
Commands.send(cmd, @args) if Commands.respond_to?(cmd)
Commands.send(cmd, @args) if Commands.method_defined?(cmd)
end

# Shortcut
Expand Down
6 changes: 6 additions & 0 deletions test/helper.rb
Expand Up @@ -70,6 +70,12 @@ def assert_command(input, expected)
assert_equal expected, Hub(input).command, "$ git #{input}"
end

# Asserts that the command will be forwarded to git without changes
def assert_forwarded(input)
cmd = Hub(input)
assert !cmd.args.changed?, "arguments were not supposed to change: #{cmd.args.inspect}"
end

# Asserts that `hub` will show a specific alias command for a
# specific shell.
#
Expand Down
5 changes: 5 additions & 0 deletions test/hub_test.rb
Expand Up @@ -711,6 +711,11 @@ def test_context_method_doesnt_hijack_git_command
assert_command 'remotes', 'git remotes'
end

def test_not_choking_on_ruby_methods
assert_forwarded 'id'
assert_forwarded 'name'
end

def test_multiple_remote_urls
stub_repo_url("git://example.com/other.git\ngit://github.com/my/repo.git")
assert_command "browse", "open http://github.com/my/repo"
Expand Down

0 comments on commit af277fd

Please sign in to comment.