Skip to content

Commit

Permalink
clone --bare: Add ".git" suffix to the directory name to clone into
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Johannes Schindelin authored and Junio C Hamano committed Aug 3, 2008
1 parent 807d869 commit 6612f87
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
10 changes: 8 additions & 2 deletions builtin-clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -389,7 +395,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);
Expand Down
7 changes: 7 additions & 0 deletions t/t5601-clone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,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

0 comments on commit 6612f87

Please sign in to comment.