Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
hub
提交
ddf79ca0
H
hub
项目概览
github
/
hub
11 个月 前同步成功
通知
3
Star
22523
Fork
2406
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hub
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ddf79ca0
编写于
4月 07, 2010
作者:
C
Chris Wanstrath
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Tweaks, 80c, docs, -f
上级
c4bda898
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
38 addition
and
23 deletion
+38
-23
README.md
README.md
+4
-3
lib/hub/commands.rb
lib/hub/commands.rb
+19
-9
test/hub_test.rb
test/hub_test.rb
+15
-11
未找到文件。
README.md
浏览文件 @
ddf79ca0
...
...
@@ -129,10 +129,11 @@ superpowers:
$ git fork
... hardcore forking action ...
> git remote add YOUR_USER git@github.com:YOUR_USER/CURRENT_REPO.git
> git remote add
-f
YOUR_USER git@github.com:YOUR_USER/CURRENT_REPO.git
Forks the original repo on GitHub and adds the new remote under your username.
It requires your GitHub token to be present; see "GitHub login" below for details.
Forks the original repo on GitHub and adds the new remote under your
username. It requires your GitHub token to be present; see "GitHub
login" below for details.
### git init
...
...
lib/hub/commands.rb
浏览文件 @
ddf79ca0
...
...
@@ -115,7 +115,7 @@ module Hub
ssh
=
args
.
delete
(
'-p'
)
url
=
ssh
?
PRIVATE
:
PUBLIC
# user/repo
args
.
last
=~
/\b(.+?)(?:\/(.+))?$/
user
,
repo
=
$1
,
$2
||
REPO
...
...
@@ -149,23 +149,26 @@ module Hub
args
.
after
"git remote add origin
#{
url
}
"
end
end
# $ hub fork
# ... hardcore forking action ...
# > git remote add -f YOUR_USER git@github.com:YOUR_USER/CURRENT_REPO.git
def
fork
(
args
)
require
'net/http'
# can't do anything without token and original owner name
if
github_user
and
github_token
and
!
OWNER
.
empty?
if
github_user
&&
github_token
&&
!
OWNER
.
empty?
if
own_repo_exists?
puts
"
#{
github_user
}
/
#{
REPO
}
already exists on GitHub"
else
fork_repo
end
if
args
.
include?
(
'--no-remote'
)
exit
else
url
=
PRIVATE
%
[
github_user
,
REPO
]
args
.
replace
%W"remote add
#{
github_user
}
#{
url
}
"
args
.
replace
%W"remote add
-f
#{
github_user
}
#{
url
}
"
args
.
after
{
puts
"new remote:
#{
github_user
}
"
}
end
end
...
...
@@ -373,7 +376,7 @@ help
USER
end
end
def
github_token
if
TOKEN
.
empty?
abort
"** No GitHub token set. See
#{
LGHCONF
}
"
...
...
@@ -465,12 +468,19 @@ help
write
.
close
end
end
# Determines whether the current user (you) has a fork of the
# current repo on GitHub.
#
# Returns a Boolean.
def
own_repo_exists?
url
=
API_REPO
%
[
USER
,
REPO
]
Net
::
HTTPSuccess
===
Net
::
HTTP
.
get_response
(
URI
(
url
))
end
# Forks the current repo using the GitHub API.
#
# Returns nothing.
def
fork_repo
url
=
API_FORK
%
[
OWNER
,
REPO
]
Net
::
HTTP
.
post_form
(
URI
(
url
),
'login'
=>
USER
,
'token'
=>
TOKEN
)
...
...
test/hub_test.rb
浏览文件 @
ddf79ca0
...
...
@@ -4,7 +4,7 @@ require 'webmock/test_unit'
class
HubTest
<
Test
::
Unit
::
TestCase
include
WebMock
def
setup
Hub
::
Commands
::
REPO
.
replace
(
"hub"
)
Hub
::
Commands
::
USER
.
replace
(
"tpw"
)
...
...
@@ -200,31 +200,34 @@ class HubTest < Test::Unit::TestCase
assert_equal
"git push origin cool-feature"
,
h
.
command
assert_equal
"git push staging cool-feature; git push qa cool-feature"
,
h
.
after
end
def
test_fork
stub_request
(
:get
,
"github.com/api/v2/yaml/repos/show/tpw/hub"
).
to_return
(
:status
=>
404
)
stub_request
(
:get
,
"github.com/api/v2/yaml/repos/show/tpw/hub"
).
to_return
(
:status
=>
404
)
stub_request
(
:post
,
"github.com/api/v2/yaml/repos/fork/defunkt/hub"
).
with
{
|
req
|
params
=
Hash
[
*
req
.
body
.
split
(
/[&=]/
)]
params
==
{
'login'
=>
'tpw'
,
'token'
=>
'abc123'
}
}
expected
=
"remote add tpw git@github.com:tpw/hub.git
\n
"
expected
=
"remote add
-f
tpw git@github.com:tpw/hub.git
\n
"
expected
<<
"new remote: tpw
\n
"
assert_equal
expected
,
hub
(
"fork"
)
{
ENV
[
'GIT'
]
=
'echo'
}
end
def
test_fork_no_remote
stub_request
(
:get
,
"github.com/api/v2/yaml/repos/show/tpw/hub"
).
to_return
(
:status
=>
404
)
stub_request
(
:get
,
"github.com/api/v2/yaml/repos/show/tpw/hub"
).
to_return
(
:status
=>
404
)
stub_request
(
:post
,
"github.com/api/v2/yaml/repos/fork/defunkt/hub"
)
assert_equal
""
,
hub
(
"fork --no-remote"
)
{
ENV
[
'GIT'
]
=
'echo'
}
end
def
test_fork_already_exists
stub_request
(
:get
,
"github.com/api/v2/yaml/repos/show/tpw/hub"
).
to_return
(
:status
=>
200
)
stub_request
(
:get
,
"github.com/api/v2/yaml/repos/show/tpw/hub"
).
to_return
(
:status
=>
200
)
expected
=
"tpw/hub already exists on GitHub
\n
"
expected
<<
"remote add tpw git@github.com:tpw/hub.git
\n
"
expected
<<
"remote add
-f
tpw git@github.com:tpw/hub.git
\n
"
expected
<<
"new remote: tpw
\n
"
assert_equal
expected
,
hub
(
"fork"
)
{
ENV
[
'GIT'
]
=
'echo'
}
end
...
...
@@ -276,7 +279,8 @@ config
end
def
test_hub_open_private
assert_command
"browse -p bmizerany/sinatra"
,
"open https://github.com/bmizerany/sinatra"
assert_command
"browse -p bmizerany/sinatra"
,
"open https://github.com/bmizerany/sinatra"
end
def
test_hub_open_self
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录