Skip to content

Commit 5672827

Browse files
harupyuranusjr
andauthored
Log commit SHA when installing package via Git URI (#10149)
Co-authored-by: Tzu-ping Chung <[email protected]>
1 parent f6b184c commit 5672827

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

news/10149.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Log the resolved commit SHA when installing a package from a Git repository.

src/pip/_internal/vcs/git.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,11 @@ def fetch_new(self, dest, url, rev_options):
281281
'checkout', '-b', branch_name, '--track', track_branch,
282282
]
283283
self.run_command(cmd_args, cwd=dest)
284+
else:
285+
sha = self.get_revision(dest)
286+
rev_options = rev_options.make_new(sha)
287+
288+
logger.info("Resolved %s to commit %s", url, rev_options.rev)
284289

285290
#: repo may contain submodules
286291
self.update_submodules(dest)

tests/functional/test_install_vcs_git.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,28 @@ def test_git_install_then_install_ref(script):
271271
assert '0.1' == version
272272

273273

274+
@pytest.mark.network
275+
@pytest.mark.parametrize('rev, expected_sha', [
276+
# Clone the default branch
277+
("", "5547fa909e83df8bd743d3978d6667497983a4b7"),
278+
# Clone a specific tag
279+
("@0.1.1", "7d654e66c8fa7149c165ddeffa5b56bc06619458"),
280+
# Clone a specific commit
281+
("@65cf0a5bdd906ecf48a0ac241c17d656d2071d56",
282+
"65cf0a5bdd906ecf48a0ac241c17d656d2071d56")
283+
])
284+
def test_install_git_logs_commit_sha(script, rev, expected_sha, tmpdir):
285+
"""
286+
Test installing from a git repository logs a commit SHA.
287+
"""
288+
url_path = "pypa/pip-test-package.git"
289+
base_local_url = _github_checkout(url_path, tmpdir)
290+
local_url = f"{base_local_url}{rev}#egg=pip-test-package"
291+
result = script.pip("install", local_url)
292+
# `[4:]` removes a 'git+' prefix
293+
assert f"Resolved {base_local_url[4:]} to commit {expected_sha}" in result.stdout
294+
295+
274296
@pytest.mark.network
275297
def test_git_with_tag_name_and_update(script, tmpdir):
276298
"""

0 commit comments

Comments
 (0)