Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
镜像
Python_Packaging_Authority
pip
提交
85dc1571
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,发现更多精彩内容 >>
提交
85dc1571
编写于
8月 22, 2017
作者:
C
Chris Jerdonek
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add Git.get_revision_sha() with tests.
上级
b2d36d26
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
114 addition
and
0 deletion
+114
-0
src/pip/_internal/vcs/git.py
src/pip/_internal/vcs/git.py
+23
-0
tests/functional/test_vcs_git.py
tests/functional/test_vcs_git.py
+91
-0
未找到文件。
src/pip/_internal/vcs/git.py
浏览文件 @
85dc1571
...
...
@@ -89,6 +89,29 @@ class Git(VersionControl):
show_stdout
=
False
,
cwd
=
temp_dir
.
path
)
def
get_revision_sha
(
self
,
dest
,
rev
):
"""
Return a commit hash for the given revision if it names a remote
branch or tag. Otherwise, return None.
Args:
dest: the repository directory.
rev: the revision name.
"""
# Pass rev to pre-filter the list.
output
=
self
.
run_command
([
'show-ref'
,
rev
],
cwd
=
dest
,
show_stdout
=
False
,
on_returncode
=
'ignore'
)
refs
=
{}
for
line
in
output
.
strip
().
splitlines
():
sha
,
ref
=
line
.
split
(
None
,
1
)
refs
[
ref
]
=
sha
sha
=
refs
.
get
(
'refs/remotes/origin/{}'
.
format
(
rev
))
if
sha
is
not
None
:
return
sha
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.
...
...
tests/functional/test_vcs_git.py
0 → 100644
浏览文件 @
85dc1571
"""
Contains functional tests of the Git class.
"""
from
pip.utils.temp_dir
import
TempDirectory
from
pip.vcs.git
import
Git
def
get_head_sha
(
script
,
dest
):
"""
Return the HEAD sha.
"""
result
=
script
.
run
(
'git'
,
'rev-parse'
,
'HEAD'
,
cwd
=
dest
)
sha
=
result
.
stdout
.
strip
()
return
sha
def
do_commit
(
script
,
dest
):
script
.
run
(
'git'
,
'commit'
,
'-q'
,
'--author'
,
'pip <pypa-dev@googlegroups.com>'
,
'--allow-empty'
,
'-m'
,
'test commit'
,
cwd
=
dest
)
sha
=
get_head_sha
(
script
,
dest
)
return
sha
def
add_commits
(
script
,
dest
,
count
):
"""
Return a list of the commit hashes from oldest to newest.
"""
shas
=
[]
for
index
in
range
(
count
):
sha
=
do_commit
(
script
,
dest
)
shas
.
append
(
sha
)
return
shas
def
check_rev
(
repo_dir
,
rev
,
expected_sha
):
git
=
Git
()
assert
git
.
get_revision_sha
(
repo_dir
,
rev
)
==
expected_sha
def
test_get_revision_sha
(
script
):
with
TempDirectory
(
kind
=
"testing"
)
as
temp
:
repo_dir
=
temp
.
path
script
.
run
(
'git'
,
'init'
,
cwd
=
repo_dir
)
shas
=
add_commits
(
script
,
repo_dir
,
count
=
6
)
local_branch_sha
=
shas
[
0
]
tag_sha
=
shas
[
1
]
origin_branch_sha
=
shas
[
2
]
upstream_branch_sha
=
shas
[
3
]
ref_sha
=
shas
[
4
]
head_sha
=
shas
[
5
]
assert
head_sha
==
shas
[
-
1
]
script
.
run
(
'git'
,
'branch'
,
'local-branch'
,
local_branch_sha
,
cwd
=
repo_dir
)
script
.
run
(
'git'
,
'tag'
,
'v1.0'
,
tag_sha
,
cwd
=
repo_dir
)
script
.
run
(
'git'
,
'update-ref'
,
'refs/remotes/origin/origin-branch'
,
origin_branch_sha
,
cwd
=
repo_dir
)
script
.
run
(
'git'
,
'update-ref'
,
'refs/remotes/upstream/upstream-branch'
,
upstream_branch_sha
,
cwd
=
repo_dir
)
script
.
run
(
'git'
,
'update-ref'
,
'refs/generic-ref'
,
ref_sha
,
cwd
=
repo_dir
)
# Test two tags pointing to the same sha.
script
.
run
(
'git'
,
'tag'
,
'v2.0'
,
tag_sha
,
cwd
=
repo_dir
)
# Test tags sharing the same suffix as another tag, both before and
# after alphabetically.
script
.
run
(
'git'
,
'tag'
,
'aaa/v1.0'
,
head_sha
,
cwd
=
repo_dir
)
script
.
run
(
'git'
,
'tag'
,
'zzz/v1.0'
,
head_sha
,
cwd
=
repo_dir
)
check_rev
(
repo_dir
,
'local-branch'
,
None
)
check_rev
(
repo_dir
,
'v1.0'
,
tag_sha
)
check_rev
(
repo_dir
,
'v2.0'
,
tag_sha
)
check_rev
(
repo_dir
,
'origin-branch'
,
origin_branch_sha
)
check_rev
(
repo_dir
,
'upstream-branch'
,
None
)
check_rev
(
repo_dir
,
'generic-ref'
,
None
)
# Test passing a valid commit hash.
check_rev
(
repo_dir
,
tag_sha
,
None
)
# Test passing a non-existent name.
check_rev
(
repo_dir
,
'does-not-exist'
,
None
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录