Skip to content

Commit 0879aa2

Browse files
Andreas EricssonJunio C Hamano
authored andcommitted
git-clone: Keep remote names when cloning unless explicitly told not to.
With this patch the following commands all clone into the local directory "repo". If repo exists, it will still barf. git-clone git://host.xz/repo.git git-clone /path/to/repo/.git git-clone host.xz:repo.git I ended up doing the same source-to-target sed'ing for all our company projects, so it was easier to add it directly to git-clone. Signed-off-by: Andreas Ericsson <ae@op5.se> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 0867b01 commit 0879aa2

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

Documentation/git-clone.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ git-clone - Clones a repository.
88

99
SYNOPSIS
1010
--------
11-
'git-clone' [-l [-s]] [-q] [-n] [-u <upload-pack>] <repository> <directory>
11+
'git-clone' [-l [-s]] [-q] [-n] [-u <upload-pack>] <repository> [<directory>]
1212

1313
DESCRIPTION
1414
-----------
@@ -68,17 +68,19 @@ OPTIONS
6868
be any URL git-fetch supports.
6969

7070
<directory>::
71-
The name of a new directory to be cloned into. It is an
72-
error to specify an existing directory.
73-
71+
The name of a new directory to clone into. The "humanish"
72+
part of the source repository is used if no directory is
73+
explicitly given ("repo" for "/path/to/repo.git" and "foo"
74+
for "host.xz:foo/.git"). Cloning into an existing directory
75+
is not allowed.
7476

7577
Author
7678
------
7779
Written by Linus Torvalds <torvalds@osdl.org>
7880

7981
Documentation
8082
--------------
81-
Documentation by Junio C Hamano.
83+
Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
8284

8385

8486
GIT

git-clone.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ if base=$(get_repo_base "$repo"); then
9696
fi
9797

9898
dir="$2"
99+
# Try using "humanish" part of source repo if user didn't specify one
100+
[ -z "$dir" ] && dir=$(echo "$repo" | sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*/||g')
99101
mkdir "$dir" &&
100102
D=$(
101103
(cd "$dir" && git-init-db && pwd)

0 commit comments

Comments
 (0)