@matheusbsbs / matheus-bagliano / commits / c6fef0bbea
Fork 0

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>

Santi Béjar committed Feb 29, 2008 at 20:16 UTC c6fef0bbea485ff8aec979177ee5c1c568fffc55
2 files changed +75 -7
git-clone.sh
+30 -7
@@ -210,11 +210,28 @@ if base=$(get_repo_base "$repo"); then
210 then
211 local=yes
212 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
233 fi
234
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')
235 [ -e "$dir" ] && die "destination directory '$dir' already exists."
236 [ yes = "$bare" ] && unset GIT_WORK_TREE
237 [ -n "$GIT_WORK_TREE" ] && [ -e "$GIT_WORK_TREE" ] &&
@@ -364,11 +381,17 @@ yes)
381 fi
382 ;;
383 *)
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" ||
393 die "fetch-pack from '$repo' failed."
394 + fi
395 ;;
396 esac
397 ;;
t/t5701-clone-local.sh
+45
@@ -11,6 +11,11 @@ test_expect_success 'preparing origin repository' '
11 git clone --bare . x &&
12 test "$(GIT_CONFIG=a.git/config git config --bool core.bare)" = true &&
13 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
19 '
20
21 test_expect_success 'local clone without .git suffix' '
@@ -71,4 +76,44 @@ test_expect_success 'local clone of repo with nonexistent ref in HEAD' '
76 git fetch &&
77 test ! -e .git/refs/remotes/origin/HEAD'
78
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 +
119 test_done