Skip to content

Commit ba375ac

Browse files
author
Linus Torvalds
committed
Make "git clone" a lot more user-friendly
This silently adds the ".git" directory component if needed, so you don't need to state it explicitly for the source. Also, it turns the source into an absolute pathname when local, so that you can use relative pathnames without losing sight of the source when we cd into the destination.
1 parent 51cb06c commit ba375ac

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

git-clone-script

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ usage() {
1010
exit 1
1111
}
1212

13+
get_repo_base() {
14+
(cd "$1" && (cd .git ; pwd)) 2> /dev/null
15+
}
16+
1317
use_local=no
1418
while
1519
case "$#,$1" in
@@ -22,7 +26,15 @@ do
2226
shift
2327
done
2428

29+
# Turn the source into an absolute path if
30+
# it is local
2531
repo="$1"
32+
local=no
33+
if base=$(get_repo_base "$repo"); then
34+
repo="$base"
35+
local=yes
36+
fi
37+
2638
dir="$2"
2739
mkdir "$dir" &&
2840
D=$(
@@ -31,8 +43,8 @@ D=$(
3143
test -d "$D" || usage
3244

3345
# We do local magic only when the user tells us to.
34-
case "$use_local" in
35-
yes)
46+
case "$local,$use_local" in
47+
yes,yes)
3648
( cd "$repo/objects" ) || {
3749
repo="$repo/.git"
3850
( cd "$repo/objects" ) || {

0 commit comments

Comments
 (0)