Skip to content

Commit 56bf038

Browse files
committed
Add test for shallow clone HEAD
1 parent 991c249 commit 56bf038

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

tests/unit/test_clone_depth.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Test that a clone depth of 1 is used and good enough when no refspec is used
2+
Test that a clone depth of 1 is used when HEAD or no refspec is used
33
44
Note: the tests don't actually run the container. Building the
55
container requires a specific repository and commit to be checked out,
@@ -25,7 +25,34 @@ def test_clone_depth():
2525
repo=URL,
2626
dry_run=True,
2727
run=False,
28-
# turn of automatic clean up of the checkout so we can inspect it
28+
# turn off automatic clean up of the checkout so we can inspect it
29+
# we also set the work directory explicitly so we know where to look
30+
cleanup_checkout=False,
31+
git_workdir=d,
32+
)
33+
app.initialize()
34+
app.start()
35+
36+
cmd = ["git", "rev-parse", "HEAD"]
37+
p = subprocess.run(cmd, stdout=subprocess.PIPE, cwd=d)
38+
assert p.stdout.strip() == b"703322e9c6635ba1835d3b92eafbabeca0042c3e"
39+
cmd = ["git", "rev-list", "--count", "HEAD"]
40+
p = subprocess.run(cmd, stdout=subprocess.PIPE, cwd=d)
41+
assert p.stdout.strip() == b"1"
42+
with open(os.path.join(d, "COMMIT")) as fp:
43+
assert fp.read() == "100\n"
44+
45+
46+
def test_clone_depth_head():
47+
"""Test a remote repository, with a refspec of 'HEAD'"""
48+
49+
with TemporaryDirectory() as d:
50+
app = Repo2Docker(
51+
repo=URL,
52+
ref="HEAD",
53+
dry_run=True,
54+
run=False,
55+
# turn off automatic clean up of the checkout so we can inspect it
2956
# we also set the work directory explicitly so we know where to look
3057
cleanup_checkout=False,
3158
git_workdir=d,
@@ -52,7 +79,7 @@ def test_clone_depth_full():
5279
ref="master",
5380
dry_run=True,
5481
run=False,
55-
# turn of automatic clean up of the checkout so we can inspect it
82+
# turn off automatic clean up of the checkout so we can inspect it
5683
# we also set the work directory explicitly so we know where to look
5784
cleanup_checkout=False,
5885
git_workdir=d,
@@ -80,7 +107,7 @@ def test_clone_depth_full2():
80107
ref="703322e",
81108
dry_run=True,
82109
run=False,
83-
# turn of automatic clean up of the checkout so we can inspect it
110+
# turn off automatic clean up of the checkout so we can inspect it
84111
# we also set the work directory explicitly so we know where to look
85112
cleanup_checkout=False,
86113
git_workdir=d,
@@ -108,7 +135,7 @@ def test_clone_depth_mid():
108135
ref="8bc4f21",
109136
dry_run=True,
110137
run=False,
111-
# turn of automatic clean up of the checkout so we can inspect it
138+
# turn off automatic clean up of the checkout so we can inspect it
112139
# we also set the work directory explicitly so we know where to look
113140
cleanup_checkout=False,
114141
git_workdir=d,

0 commit comments

Comments
 (0)