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

[PATCH 2/2] clone --bare: Add ".git" suffix to the directory name to clone into

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Aug 1, 2008, 14:01 UTC
Message-ID
<alpine.DEB.1.00.0808011601200.9611@pacific.mpi-cbg.de.mpi-cbg.de>
In-Reply-To
<alpine.DEB.1.00.0808011600170.9611@pacific.mpi-cbg.de.mpi-cbg.de>

We have a tradition that bare repositories live in directories ending in ".git". To make this more a convention than just a tradition, teach "git clone --bare" to add a ".git" suffix to the directory name.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
	This patch is only conceptionally dependent on patch 1/2.
 builtin-clone.c  |   10 ++++++++--
 t/t5601-clone.sh |    7 +++++++
 2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/builtin-clone.c b/builtin-clone.c
index a45179c..82f5b67 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -95,7 +95,7 @@ static char *get_repo_path(const char *repo, int *is_bundle)
 	return NULL;
 }
 
-static char *guess_dir_name(const char *repo, int is_bundle)
+static char *guess_dir_name(const char *repo, int is_bundle, int is_bare)
 {
 	const char *end = repo + strlen(repo), *start;
 
@@ -131,6 +131,12 @@ static char *guess_dir_name(const char *repo, int is_bundle)
 			end -= 4;
 	}
 
+	if (is_bare) {
+		char *result = xmalloc(end - start + 5);
+		sprintf(result, "%.*s.git", (int)(end - start), start);
+		return result;
+	}
+
 	return xstrndup(start, end - start);
 }
 
@@ -388,7 +394,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	if (argc == 2)
 		dir = xstrdup(argv[1]);
 	else
-		dir = guess_dir_name(repo_name, is_bundle);
+		dir = guess_dir_name(repo_name, is_bundle, option_bare);
 
 	if (!stat(dir, &buf))
 		die("destination directory '%s' already exists.", dir);
diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh
index 4b2533f..e0a68ab 100755
--- a/t/t5601-clone.sh
+++ b/t/t5601-clone.sh
@@ -80,4 +80,11 @@ test_expect_success 'clone --mirror' '
 
 '
 
+test_expect_success 'clone --bare names the local repository <name>.git' '
+
+	git clone --bare src &&
+	test -d src.git
+
+'
+
 test_done
-- 
1.6.0.rc1.46.g279e5
Previous: Johannes SchindelinNext: Marcus Griep
Message 2 of 9 in “clone: Add an option to set up a mirror”
  1. 1/2 clone: Add an option to set up a mirrorJohannes Schindelin, Aug 1, 2008
  2. 2/2 clone --bare: Add ".git" suffix to the directory name to clone intoJohannes Schindelin, Aug 1, 2008
  3. Marcus GriepAug 1, 2008
  4. Bert WesargAug 1, 2008
  5. Miklos VajnaAug 1, 2008
  6. Junio C HamanoAug 2, 2008
  7. clone: Add an option to set up a mirrorJohannes Schindelin, Aug 2, 2008
  8. Johannes SchindelinAug 2, 2008
  9. Junio C HamanoAug 2, 2008

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.