@matheusbsbs / matheus-bagliano / commits / 6612f877cc
Fork 0

clone --bare: Add ".git" suffix to the directory name to clone into

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Aug 1, 2008 at 16:01 UTC 6612f877cc94e80cd0c7393a8ea6bfea69146b3c
2 files changed +15 -2
builtin-clone.c
+8 -2
@@ -95,7 +95,7 @@ static char *get_repo_path(const char *repo, int *is_bundle)
95 return NULL;
96 }
97
98 -static char *guess_dir_name(const char *repo, int is_bundle)
98 +static char *guess_dir_name(const char *repo, int is_bundle, int is_bare)
99 {
100 const char *end = repo + strlen(repo), *start;
101
@@ -131,6 +131,12 @@ static char *guess_dir_name(const char *repo, int is_bundle)
131 end -= 4;
132 }
133
134 + if (is_bare) {
135 + char *result = xmalloc(end - start + 5);
136 + sprintf(result, "%.*s.git", (int)(end - start), start);
137 + return result;
138 + }
139 +
140 return xstrndup(start, end - start);
141 }
142
@@ -389,7 +395,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
395 if (argc == 2)
396 dir = xstrdup(argv[1]);
397 else
392 - dir = guess_dir_name(repo_name, is_bundle);
398 + dir = guess_dir_name(repo_name, is_bundle, option_bare);
399
400 if (!stat(dir, &buf))
401 die("destination directory '%s' already exists.", dir);
t/t5601-clone.sh
+7
@@ -82,4 +82,11 @@ test_expect_success 'clone --mirror' '
82
83 '
84
85 +test_expect_success 'clone --bare names the local repository <name>.git' '
86 +
87 + git clone --bare src &&
88 + test -d src.git
89 +
90 +'
91 +
92 test_done