Add test for shallow clone HEAD
MODIFY
tests/unit/test_clone_depth.py
tests/unit/test_clone_depth.py
"""
-Test that a clone depth of 1 is used and good enough when no refspec is used
+Test that a clone depth of 1 is used when HEAD or no refspec is used
Note: the tests don't actually run the container. Building the
container requires a specific repository and commit to be checked out,
@@ -25,7 +25,34 @@ def test_clone_depth():
repo=URL,
dry_run=True,
run=False,
- # turn of automatic clean up of the checkout so we can inspect it
+ # turn off automatic clean up of the checkout so we can inspect it
+ # we also set the work directory explicitly so we know where to look
+ cleanup_checkout=False,
+ git_workdir=d,
+ )
+ app.initialize()
+ app.start()
+
+ cmd = ["git", "rev-parse", "HEAD"]
+ p = subprocess.run(cmd, stdout=subprocess.PIPE, cwd=d)
+ assert p.stdout.strip() == b"703322e9c6635ba1835d3b92eafbabeca0042c3e"
+ cmd = ["git", "rev-list", "--count", "HEAD"]
+ p = subprocess.run(cmd, stdout=subprocess.PIPE, cwd=d)
+ assert p.stdout.strip() == b"1"
+ with open(os.path.join(d, "COMMIT")) as fp:
+ assert fp.read() == "100\n"
+
+
+def test_clone_depth_head():
+ """Test a remote repository, with a refspec of 'HEAD'"""
+
+ with TemporaryDirectory() as d:
+ app = Repo2Docker(
+ repo=URL,
+ ref="HEAD",
+ dry_run=True,
+ run=False,
+ # turn off automatic clean up of the checkout so we can inspect it
# we also set the work directory explicitly so we know where to look
cleanup_checkout=False,
git_workdir=d,
@@ -52,7 +79,7 @@ def test_clone_depth_full():
ref="master",
dry_run=True,
run=False,
- # turn of automatic clean up of the checkout so we can inspect it
+ # turn off automatic clean up of the checkout so we can inspect it
# we also set the work directory explicitly so we know where to look
cleanup_checkout=False,
git_workdir=d,
@@ -80,7 +107,7 @@ def test_clone_depth_full2():
ref="703322e",
dry_run=True,
run=False,
- # turn of automatic clean up of the checkout so we can inspect it
+ # turn off automatic clean up of the checkout so we can inspect it
# we also set the work directory explicitly so we know where to look
cleanup_checkout=False,
git_workdir=d,
@@ -108,7 +135,7 @@ def test_clone_depth_mid():
ref="8bc4f21",
dry_run=True,
run=False,
- # turn of automatic clean up of the checkout so we can inspect it
+ # turn off automatic clean up of the checkout so we can inspect it
# we also set the work directory explicitly so we know where to look
cleanup_checkout=False,
git_workdir=d,

Add test for shallow clone HEAD