Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
hub
提交
d8a09d0f
H
hub
项目概览
github
/
hub
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
d8a09d0f
编写于
3月 17, 2011
作者:
M
Mislav Marohnić
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support git aliases
closes #54
上级
ff40b54e
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
58 addition
and
9 deletion
+58
-9
lib/hub/commands.rb
lib/hub/commands.rb
+25
-0
lib/hub/context.rb
lib/hub/context.rb
+4
-0
lib/hub/runner.rb
lib/hub/runner.rb
+3
-8
test/hub_test.rb
test/hub_test.rb
+26
-1
未找到文件。
lib/hub/commands.rb
浏览文件 @
d8a09d0f
...
...
@@ -41,6 +41,22 @@ module Hub
API_FORK
=
'http://github.com/api/v2/yaml/repos/fork/%s/%s'
API_CREATE
=
'http://github.com/api/v2/yaml/repos/create'
def
run
(
args
)
# Hack to emulate git-style
args
.
unshift
'help'
if
args
.
grep
(
/^[^-]|version|exec-path$|html-path/
).
empty?
cmd
=
args
[
0
]
expanded_args
=
expand_alias
(
cmd
)
cmd
=
expanded_args
[
0
]
if
expanded_args
# git commands can have dashes
cmd
=
cmd
.
sub
(
/(\w)-/
,
'\1_'
)
if
method_defined?
(
cmd
)
and
cmd
!=
'run'
args
[
0
,
1
]
=
expanded_args
if
expanded_args
send
(
cmd
,
args
)
end
end
# $ hub clone rtomayko/tilt
# > git clone git://github.com/rtomayko/tilt.
#
...
...
@@ -687,5 +703,14 @@ help
response
.
error!
unless
Net
::
HTTPSuccess
===
response
end
def
expand_alias
(
cmd
)
if
expanded
=
git_alias_for
(
cmd
)
if
expanded
.
index
(
'!'
)
!=
0
require
'shellwords'
unless
expanded
.
respond_to?
:shellsplit
expanded
.
shellsplit
end
end
end
end
end
lib/hub/context.rb
浏览文件 @
d8a09d0f
...
...
@@ -106,6 +106,10 @@ module Hub
GIT_CONFIG
[
'config --bool hub.http-clone'
]
==
'true'
end
def
git_alias_for
(
name
)
GIT_CONFIG
[
"config alias.
#{
name
}
"
]
end
# Core.repositoryformatversion should exist for all git
# repositories, and be blank for all non-git repositories. If
# there's a better config setting to check here, this can be
...
...
lib/hub/runner.rb
浏览文件 @
d8a09d0f
...
...
@@ -9,13 +9,7 @@ module Hub
def
initialize
(
*
args
)
@args
=
Args
.
new
(
args
)
# Hack to emulate git-style
@args
.
unshift
'help'
if
@args
.
grep
(
/^[^-]|version|exec-path$|html-path/
).
empty?
# git commands can have dashes
cmd
=
@args
[
0
].
sub
(
/(\w)-/
,
'\1_'
)
Commands
.
send
(
cmd
,
@args
)
if
Commands
.
method_defined?
(
cmd
)
Commands
.
run
(
@args
)
end
# Shortcut
...
...
@@ -36,7 +30,8 @@ module Hub
def
commands
args
.
commands
.
map
do
|
cmd
|
if
cmd
.
respond_to?
(
:join
)
cmd
.
map
{
|
c
|
c
.
index
(
' '
)
?
"'
#{
c
}
'"
:
c
}.
join
(
' '
)
# a simplified `Shellwords.join` but it's OK since this is only used to inspect
cmd
.
map
{
|
c
|
(
c
.
index
(
' '
)
||
c
.
empty?
)
?
"'
#{
c
}
'"
:
c
}.
join
(
' '
)
else
cmd
.
to_s
end
...
...
test/hub_test.rb
浏览文件 @
d8a09d0f
...
...
@@ -30,7 +30,9 @@ class HubTest < Test::Unit::TestCase
Hub
::
Context
::
REMOTES
.
clear
@git
=
Hub
::
Context
::
GIT_CONFIG
.
replace
(
Hash
.
new
{
|
h
,
k
|
unless
k
.
index
(
'config alias.'
)
==
0
raise
ArgumentError
,
"`git
#{
k
}
` not stubbed"
end
}).
update
(
'remote'
=>
"mislav
\n
origin"
,
'symbolic-ref -q HEAD'
=>
'refs/heads/master'
,
...
...
@@ -114,6 +116,25 @@ class HubTest < Test::Unit::TestCase
assert_forwarded
"clone ./test"
end
def
test_alias_expand
stub_alias
'c'
,
'clone --bare'
input
=
"c rtomayko/ronn"
command
=
"git clone --bare git://github.com/rtomayko/ronn.git"
assert_command
input
,
command
end
def
test_alias_expand_advanced
stub_alias
'c'
,
'clone --template="white space"'
input
=
"c rtomayko/ronn"
command
=
"git clone '--template=white space' git://github.com/rtomayko/ronn.git"
assert_command
input
,
command
end
def
test_alias_doesnt_expand_for_unknown_commands
stub_alias
'c'
,
'compute --fast'
assert_forwarded
"c rtomayko/ronn"
end
def
test_remote_origin
input
=
"remote add origin"
command
=
"git remote add origin git://github.com/tpw/hub.git"
...
...
@@ -771,6 +792,10 @@ config
@git
.
replace
({})
end
def
stub_alias
(
name
,
value
)
@git
[
"config alias.
#{
name
}
"
]
=
value
end
def
stub_existing_fork
(
user
)
stub_fork
(
user
,
200
)
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录