-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit de9bfa2
Showing
4 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
task :default => :test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
chris@airistotle.local.6231 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/usr/bin/env ruby | ||
|
||
class Hub | ||
PRIVATE = 'git@github.com:%s/%s.git' | ||
PUBLIC = 'git://github.com/%s/%s.git' | ||
USER = `git config --global github.user`.chomp | ||
REPO = `basename $(pwd)`.chomp | ||
|
||
attr_reader :args, :after | ||
def initialize(*args) | ||
@args = args | ||
end | ||
|
||
def clone | ||
ssh = @args.delete('-p') | ||
@args.each_with_index do |arg, i| | ||
if arg.scan('/').size == 1 && !arg.include?(':') | ||
url = ssh ? PRIVATE : PUBLIC | ||
@args[i] = url % arg.split('/') | ||
end | ||
end | ||
end | ||
|
||
def remote | ||
if @args[1] == 'add' | ||
if @args.delete('-g') | ||
ssh = @args.delete('-p') | ||
user = @args.last | ||
url = ssh ? PRIVATE : PUBLIC | ||
@args << url % [ user, REPO ] | ||
end | ||
end | ||
end | ||
|
||
def init | ||
if @args.delete('-g') | ||
url = PRIVATE % [ USER, REPO ] | ||
@after = "git remote add origin #{url}" | ||
end | ||
end | ||
|
||
def execute | ||
if respond_to?(@args[0]) | ||
send(@args[0]) | ||
end | ||
|
||
if @after | ||
if system("git", *@args) | ||
exec @after | ||
else | ||
exit 1 | ||
end | ||
else | ||
exec "git", *@args | ||
end | ||
end | ||
end | ||
|
||
if $0 == __FILE__ | ||
Hub.new(*ARGV).execute | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require 'test/unit' | ||
load File.dirname(__FILE__) + '/../bin/hub' | ||
|
||
class HubTest < Test::Unit::TestCase | ||
def hub(args) | ||
args = args.split(' ') | ||
hub = Hub.new(*args) | ||
hub.send(args[0]) | ||
hub | ||
end | ||
|
||
def test_private_clone | ||
h = hub("clone -p rtomayko/ron") | ||
assert_equal 'git@github.com:rtomayko/ron.git', h.args.last | ||
end | ||
|
||
def test_public_clone | ||
h = hub("clone rtomayko/ron") | ||
assert_equal 'git://github.com/rtomayko/ron.git', h.args.last | ||
end | ||
|
||
def test_private_remote | ||
h = hub("remote add -g -p rtomayko") | ||
assert_equal 'git@github.com:rtomayko/hub.git', h.args.last | ||
end | ||
|
||
def test_public_remote | ||
h = hub("remote add -g rtomayko") | ||
assert_equal 'git://github.com/rtomayko/hub.git', h.args.last | ||
end | ||
|
||
def test_init | ||
h = hub("init -g") | ||
assert_equal 'git remote add origin git@github.com:defunkt/hub.git', h.after | ||
end | ||
end |