Skip to content

Commit c6fef0b

Browse files
sbejargitster
authored andcommitted
clone: support cloning full bundles
The "humanish" part of a bundle is made removing the ".bundle" suffix. Signed-off-by: Santi Béjar <sbejar@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 97b97c5 commit c6fef0b

File tree

2 files changed

+75
-7
lines changed

2 files changed

+75
-7
lines changed

git-clone.sh

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,28 @@ if base=$(get_repo_base "$repo"); then
210210
then
211211
local=yes
212212
fi
213+
elif test -f "$repo"
214+
then
215+
case "$repo" in /*) ;; *) repo="$PWD/$repo" ;; esac
216+
fi
217+
218+
# Decide the directory name of the new repository
219+
if test -n "$2"
220+
then
221+
dir="$2"
222+
else
223+
# Derive one from the repository name
224+
# Try using "humanish" part of source repo if user didn't specify one
225+
if test -f "$repo"
226+
then
227+
# Cloning from a bundle
228+
dir=$(echo "$repo" | sed -e 's|/*\.bundle$||' -e 's|.*/||g')
229+
else
230+
dir=$(echo "$repo" |
231+
sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g')
232+
fi
213233
fi
214234

215-
dir="$2"
216-
# Try using "humanish" part of source repo if user didn't specify one
217-
[ -z "$dir" ] && dir=$(echo "$repo" | sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g')
218235
[ -e "$dir" ] && die "destination directory '$dir' already exists."
219236
[ yes = "$bare" ] && unset GIT_WORK_TREE
220237
[ -n "$GIT_WORK_TREE" ] && [ -e "$GIT_WORK_TREE" ] &&
@@ -364,11 +381,17 @@ yes)
364381
fi
365382
;;
366383
*)
367-
case "$upload_pack" in
368-
'') git-fetch-pack --all -k $quiet $depth $no_progress "$repo";;
369-
*) git-fetch-pack --all -k $quiet "$upload_pack" $depth $no_progress "$repo" ;;
370-
esac >"$GIT_DIR/CLONE_HEAD" ||
384+
if [ -f "$repo" ] ; then
385+
git bundle unbundle "$repo" > "$GIT_DIR/CLONE_HEAD" ||
386+
die "unbundle from '$repo' failed."
387+
else
388+
case "$upload_pack" in
389+
'') git-fetch-pack --all -k $quiet $depth $no_progress "$repo";;
390+
*) git-fetch-pack --all -k \
391+
$quiet "$upload_pack" $depth $no_progress "$repo" ;;
392+
esac >"$GIT_DIR/CLONE_HEAD" ||
371393
die "fetch-pack from '$repo' failed."
394+
fi
372395
;;
373396
esac
374397
;;

t/t5701-clone-local.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ test_expect_success 'preparing origin repository' '
1111
git clone --bare . x &&
1212
test "$(GIT_CONFIG=a.git/config git config --bool core.bare)" = true &&
1313
test "$(GIT_CONFIG=x/config git config --bool core.bare)" = true
14+
git bundle create b1.bundle --all HEAD &&
15+
git bundle create b2.bundle --all &&
16+
mkdir dir &&
17+
cp b1.bundle dir/b3
18+
cp b1.bundle b4
1419
'
1520

1621
test_expect_success 'local clone without .git suffix' '
@@ -71,4 +76,44 @@ test_expect_success 'local clone of repo with nonexistent ref in HEAD' '
7176
git fetch &&
7277
test ! -e .git/refs/remotes/origin/HEAD'
7378

79+
test_expect_success 'bundle clone without .bundle suffix' '
80+
cd "$D" &&
81+
git clone dir/b3 &&
82+
cd b3 &&
83+
git fetch
84+
'
85+
86+
test_expect_success 'bundle clone with .bundle suffix' '
87+
cd "$D" &&
88+
git clone b1.bundle &&
89+
cd b1 &&
90+
git fetch
91+
'
92+
93+
test_expect_success 'bundle clone from b4' '
94+
cd "$D" &&
95+
git clone b4 bdl &&
96+
cd bdl &&
97+
git fetch
98+
'
99+
100+
test_expect_success 'bundle clone from b4.bundle that does not exist' '
101+
cd "$D" &&
102+
if git clone b4.bundle bb
103+
then
104+
echo "Oops, should have failed"
105+
false
106+
else
107+
echo happy
108+
fi
109+
'
110+
111+
test_expect_success 'bundle clone with nonexistent HEAD' '
112+
cd "$D" &&
113+
git clone b2.bundle b2 &&
114+
cd b2 &&
115+
git fetch
116+
test ! -e .git/refs/heads/master
117+
'
118+
74119
test_done

0 commit comments

Comments
 (0)