Skip to content

Commit defe13a

Browse files
raalkmlgitster
authored andcommitted
Fix clone to setup the origin if its name ends with .git
The problem is visible when cloning a local repo. The cloned repository will have the origin url setup incorrectly: the origin name will be copied verbatim in origin url of the cloned repository. Normally, the name is to be expanded into absolute path. Signed-off-by: Alex Riesen <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 23fcdc7 commit defe13a

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

git-clone.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ usage() {
2020
get_repo_base() {
2121
(
2222
cd "`/bin/pwd`" &&
23-
cd "$1" &&
23+
cd "$1" || cd "$1.git" &&
2424
{
2525
cd .git
2626
pwd

t/t5701-clone-local.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/sh
2+
3+
test_description='test local clone'
4+
. ./test-lib.sh
5+
6+
D=`pwd`
7+
8+
test_expect_success 'preparing origin repository' '
9+
: >file && git add . && git commit -m1 &&
10+
git clone --bare . a.git &&
11+
git clone --bare . x
12+
'
13+
14+
test_expect_success 'local clone without .git suffix' '
15+
cd "$D" &&
16+
git clone -l -s a b &&
17+
cd b &&
18+
git fetch
19+
'
20+
21+
test_expect_success 'local clone with .git suffix' '
22+
cd "$D" &&
23+
git clone -l -s a.git c &&
24+
cd c &&
25+
git fetch
26+
'
27+
28+
test_expect_success 'local clone from x' '
29+
cd "$D" &&
30+
git clone -l -s x y &&
31+
cd y &&
32+
git fetch
33+
'
34+
35+
test_expect_success 'local clone from x.git that does not exist' '
36+
cd "$D" &&
37+
if git clone -l -s x.git z
38+
then
39+
echo "Oops, should have failed"
40+
false
41+
else
42+
echo happy
43+
fi
44+
'
45+
46+
test_done

0 commit comments

Comments
 (0)