Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
镜像
Python_Packaging_Authority
pip
提交
15d058ed
P
pip
项目概览
镜像
/
Python_Packaging_Authority
/
pip
12 个月 前同步成功
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
pip
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
15d058ed
编写于
8月 22, 2017
作者:
C
Chris Jerdonek
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Start using Git.get_revision_sha().
上级
85dc1571
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
20 addition
and
129 deletion
+20
-129
src/pip/_internal/vcs/git.py
src/pip/_internal/vcs/git.py
+11
-49
tests/functional/test_install_vcs_git.py
tests/functional/test_install_vcs_git.py
+9
-68
tests/unit/test_vcs.py
tests/unit/test_vcs.py
+0
-12
未找到文件。
src/pip/_internal/vcs/git.py
浏览文件 @
15d058ed
...
...
@@ -113,35 +113,29 @@ class Git(VersionControl):
return
refs
.
get
(
'refs/tags/{}'
.
format
(
rev
))
def
check_rev_options
(
self
,
dest
,
rev_options
):
"""Check the revision options before checkout
to compensate that tags
and branches may need origin/ as a prefix.
"""Check the revision options before checkout
.
Returns a new RevOptions object for the SHA1 of the branch or tag
if found.
Args:
rev_options: a RevOptions object.
"""
revisions
=
self
.
get_short_refs
(
dest
)
rev
=
rev_options
.
arg_rev
origin_rev
=
'origin/%s'
%
rev
if
origin_rev
in
revisions
:
# remote branch
return
rev_options
.
make_new
(
revisions
[
origin_rev
])
elif
rev
in
revisions
:
# a local tag or branch name
return
rev_options
.
make_new
(
revisions
[
rev
])
sha
=
self
.
get_revision_sha
(
dest
,
rev
)
# Do not show a warning for the common case of something that has
# the form of a Git commit hash.
if
sha
is
None
:
if
not
looks_like_hash
(
rev
):
logger
.
warning
(
"Did not find branch or tag '%s', assuming ref or revision.
"
,
"Did not find branch or tag '%s', assuming revision or ref
"
,
rev
,
)
return
rev_options
return
rev_options
.
make_new
(
sha
)
def
is_commit_id_equal
(
self
,
dest
,
name
):
"""
Return whether the current commit hash equals the given name.
...
...
@@ -221,38 +215,6 @@ class Git(VersionControl):
[
'rev-parse'
,
'HEAD'
],
show_stdout
=
False
,
cwd
=
location
)
return
current_rev
.
strip
()
def
get_full_refs
(
self
,
location
):
"""Yields tuples of (commit, ref) for branches and tags"""
output
=
self
.
run_command
([
'show-ref'
],
show_stdout
=
False
,
cwd
=
location
)
for
line
in
output
.
strip
().
splitlines
():
commit
,
ref
=
line
.
split
(
' '
,
1
)
yield
commit
.
strip
(),
ref
.
strip
()
def
is_ref_remote
(
self
,
ref
):
return
ref
.
startswith
(
'refs/remotes/'
)
def
is_ref_branch
(
self
,
ref
):
return
ref
.
startswith
(
'refs/heads/'
)
def
is_ref_tag
(
self
,
ref
):
return
ref
.
startswith
(
'refs/tags/'
)
def
get_short_refs
(
self
,
location
):
"""Return map of named refs (branches or tags) to commit hashes."""
rv
=
{}
for
commit
,
ref
in
self
.
get_full_refs
(
location
):
ref_name
=
None
if
self
.
is_ref_remote
(
ref
):
ref_name
=
ref
[
len
(
'refs/remotes/'
):]
elif
self
.
is_ref_branch
(
ref
):
ref_name
=
ref
[
len
(
'refs/heads/'
):]
elif
self
.
is_ref_tag
(
ref
):
ref_name
=
ref
[
len
(
'refs/tags/'
):]
if
ref_name
is
not
None
:
rv
[
ref_name
]
=
commit
return
rv
def
_get_subdirectory
(
self
,
location
):
"""Return the relative path of setup.py to the git repo root."""
# find the repo root
...
...
tests/functional/test_install_vcs_git.py
浏览文件 @
15d058ed
...
...
@@ -9,55 +9,6 @@ from tests.lib.git_submodule_helpers import (
)
@
pytest
.
mark
.
network
def
test_get_short_refs_should_return_tag_name_and_commit_pair
(
script
):
version_pkg_path
=
_create_test_package
(
script
)
script
.
run
(
'git'
,
'tag'
,
'0.1'
,
cwd
=
version_pkg_path
)
script
.
run
(
'git'
,
'tag'
,
'0.2'
,
cwd
=
version_pkg_path
)
commit
=
script
.
run
(
'git'
,
'rev-parse'
,
'HEAD'
,
cwd
=
version_pkg_path
).
stdout
.
strip
()
git
=
Git
()
result
=
git
.
get_short_refs
(
version_pkg_path
)
assert
result
[
'0.1'
]
==
commit
,
result
assert
result
[
'0.2'
]
==
commit
,
result
@
pytest
.
mark
.
network
def
test_get_short_refs_should_return_branch_name_and_commit_pair
(
script
):
version_pkg_path
=
_create_test_package
(
script
)
script
.
run
(
'git'
,
'branch'
,
'branch0.1'
,
cwd
=
version_pkg_path
)
commit
=
script
.
run
(
'git'
,
'rev-parse'
,
'HEAD'
,
cwd
=
version_pkg_path
).
stdout
.
strip
()
git
=
Git
()
result
=
git
.
get_short_refs
(
version_pkg_path
)
assert
result
[
'master'
]
==
commit
,
result
assert
result
[
'branch0.1'
]
==
commit
,
result
@
pytest
.
mark
.
network
def
test_get_short_refs_should_ignore_no_branch
(
script
):
version_pkg_path
=
_create_test_package
(
script
)
script
.
run
(
'git'
,
'branch'
,
'branch0.1'
,
cwd
=
version_pkg_path
)
commit
=
script
.
run
(
'git'
,
'rev-parse'
,
'HEAD'
,
cwd
=
version_pkg_path
).
stdout
.
strip
()
# current branch here is "* (nobranch)"
script
.
run
(
'git'
,
'checkout'
,
commit
,
cwd
=
version_pkg_path
,
expect_stderr
=
True
,
)
git
=
Git
()
result
=
git
.
get_short_refs
(
version_pkg_path
)
assert
result
[
'master'
]
==
commit
,
result
assert
result
[
'branch0.1'
]
==
commit
,
result
@
pytest
.
mark
.
network
def
test_is_commit_id_equal
(
script
):
"""
...
...
@@ -78,34 +29,24 @@ def test_is_commit_id_equal(script):
assert
not
git
.
is_commit_id_equal
(
version_pkg_path
,
None
)
@
patch
(
'pip._internal.vcs.git.Git.get_
short_refs
'
)
def
test_check_rev_options_
should_handle_branch_name
(
get_refs
_mock
):
get_
refs_mock
.
return_value
=
{
'master'
:
'123456'
,
'0.1'
:
'abc123'
}
@
patch
(
'pip._internal.vcs.git.Git.get_
revision_sha
'
)
def
test_check_rev_options_
ref_exists
(
get_sha
_mock
):
get_
sha_mock
.
return_value
=
'123456'
git
=
Git
()
rev_options
=
git
.
make_rev_options
(
'
master
'
)
rev_options
=
git
.
make_rev_options
(
'
develop
'
)
new_options
=
git
.
check_rev_options
(
'.'
,
rev_options
)
assert
new_options
.
rev
==
'123456'
@
patch
(
'pip._internal.vcs.git.Git.get_
short_refs
'
)
def
test_check_rev_options_
should_handle_tag_name
(
get_refs
_mock
):
get_
refs_mock
.
return_value
=
{
'master'
:
'123456'
,
'0.1'
:
'abc123'
}
@
patch
(
'pip._internal.vcs.git.Git.get_
revision_sha
'
)
def
test_check_rev_options_
ref_not_found
(
get_sha
_mock
):
get_
sha_mock
.
return_value
=
None
git
=
Git
()
rev_options
=
git
.
make_rev_options
(
'
0.1
'
)
rev_options
=
git
.
make_rev_options
(
'
develop
'
)
new_options
=
git
.
check_rev_options
(
'.'
,
rev_options
)
assert
new_options
.
rev
==
'abc123'
@
patch
(
'pip._internal.vcs.git.Git.get_short_refs'
)
def
test_check_rev_options_should_handle_ambiguous_commit
(
get_refs_mock
):
get_refs_mock
.
return_value
=
{
'master'
:
'123456'
,
'0.1'
:
'123456'
}
git
=
Git
()
rev_options
=
git
.
make_rev_options
(
'0.1'
)
new_options
=
git
.
check_rev_options
(
'.'
,
rev_options
)
assert
new_options
.
rev
==
'123456'
assert
new_options
.
rev
==
'develop'
@
patch
(
'pip._internal.vcs.git.Git.get_short_refs'
)
...
...
tests/unit/test_vcs.py
浏览文件 @
15d058ed
...
...
@@ -74,21 +74,9 @@ def test_rev_options_make_new():
def
git
():
git_url
=
'http://github.com/pypa/pip-test-package'
sha
=
'5547fa909e83df8bd743d3978d6667497983a4b7'
refs
=
{
'0.1'
:
'a8992fc7ee17e5b9ece022417b64594423caca7c'
,
'0.1.1'
:
'7d654e66c8fa7149c165ddeffa5b56bc06619458'
,
'0.1.2'
:
'f1c1020ebac81f9aeb5c766ff7a772f709e696ee'
,
'foo'
:
sha
,
'bar'
:
sha
,
'master'
:
sha
,
'origin/master'
:
sha
,
'origin/HEAD'
:
sha
,
}
git
=
Git
()
git
.
get_url
=
Mock
(
return_value
=
git_url
)
git
.
get_revision
=
Mock
(
return_value
=
sha
)
git
.
get_short_refs
=
Mock
(
return_value
=
refs
)
return
git
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录