git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] clone: ignore --depth when cloning locally (implicitly --local)

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Feb 26, 2009, 23:31 UTC
Message-ID
<5adb270495925f887a1101c6f63828883e1b9b2c.1235690903u.git.johannes.schindelin@gmx.de>
In-Reply-To
<alpine.DEB.1.00.0902262352380.10279@pacific.mpi-cbg.de>

When cloning locally, we default to --local, as it makes the whole operation fast and efficient.

As the most common intent of cloning with a --depth parameter is to save space, and --local saves more space than --depth ever can, warn the user and ignore the --depth parameter when cloning locally.

Should --depth be desired, the user can always force proper cloning by passing the --no-hardlinks parameter, or by using a file:// URL.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 Documentation/git-clone.txt |    4 ++++
 builtin-clone.c             |    5 ++++-
 t/t5701-clone-local.sh      |   14 ++++++++++++++
 3 files changed, 22 insertions(+), 1 deletions(-)
diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt
index 95f08b9..9b8b389 100644
--- a/Documentation/git-clone.txt
+++ b/Documentation/git-clone.txt
@@ -138,6 +138,10 @@ then the cloned repository will become corrupt.
 	are only interested in the recent history of a large project
 	with a long history, and would want to send in fixes
 	as patches.
++
+This option is ignored when cloning locally; to force a shallow
+clone even locally, use the `--no-hardlinks` option, or a
+'file://' location.
 
 <repository>::
 	The (possibly remote) repository to clone from.  See the
diff --git a/builtin-clone.c b/builtin-clone.c
index 5540372..73d5a76 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -511,8 +511,11 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	refspec.src = src_ref_prefix;
 	refspec.dst = branch_top.buf;
 
-	if (path && !is_bundle && use_local_hardlinks)
+	if (path && !is_bundle && use_local_hardlinks) {
+		if (option_depth)
+			warning("Ignoring --depth for local clone");
 		refs = clone_local(path, git_dir);
+	}
 	else {
 		struct remote *remote = remote_get(argv[0]);
 		transport = transport_get(remote, remote->url[0]);
diff --git a/t/t5701-clone-local.sh b/t/t5701-clone-local.sh
index 3559d17..8600539 100755
--- a/t/t5701-clone-local.sh
+++ b/t/t5701-clone-local.sh
@@ -132,4 +132,18 @@ test_expect_success 'clone empty repository' '
 	 test $actual = $expected)
 '
 
+test_expect_success 'clone --depth locally ignores --depth' '
+	test_commit meredith chivers && git tag -d meredith &&
+	test_commit lisa diamond && git tag -d lisa &&
+	git clone --depth 1 . depth 2> out.err &&
+	grep "warning: Ignoring --depth for local clone" out.err &&
+	test 2 -lt $(cd depth && git rev-list master | wc -l)
+'
+
+test_expect_success '--depth is not ignored with --no-hardlinks' '
+	git clone --depth 1 --no-hardlinks . depth2 2> out.err &&
+	! grep "warning: Ignoring --depth for local clone" out.err &&
+	test 2 = $(cd depth2 && git rev-list master | wc -l)
+'
+
 test_done
-- 
1.6.2.rc2.404.g8394e
Previous: Jeff King
Message 13 of 13 in “clone: ignore --depth when cloning locally (implicitly --local)”
  1. clone: ignore --depth when cloning locally (implicitly --local)Johannes Schindelin, Feb 26, 2009
  2. Junio C HamanoFeb 26, 2009
  3. Johannes SchindelinFeb 26, 2009
  4. 0/2 shallow clone stuffJohannes Schindelin, Feb 26, 2009
  5. Junio C HamanoFeb 27, 2009
  6. 1/2 clone: do not ignore --no-hardlinksJohannes Schindelin, Feb 26, 2009
  7. Jeff KingFeb 27, 2009
  8. Junio C HamanoFeb 27, 2009
  9. Junio C HamanoFeb 27, 2009
  10. Junio C HamanoFeb 27, 2009
  11. Daniel BarkalowFeb 27, 2009
  12. Jeff KingFeb 27, 2009
  13. 2/2 clone: ignore --depth when cloning locally (implicitly --local)Johannes Schindelin, Feb 26, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.