Skip to contentSkip to conversation

clone: support cloning full bundles

PATCH In review Santi Béjar 2 participants 3 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 clone: support cloning full bundles

The "humanish" part of a bundle is made removing the ".bundle" suffix.

---
Hi,

Just in case .bundle is the definitive suffix.

Changes since v2:

. fixed the && [ -f "$repo" ] test
. make "offically" the .bundle suffix
. test that "git fetch" works after the cloning
. additional tests

Santi

 git-clone.sh           |   19 ++++++++++++++-----
 t/t5701-clone-local.sh |   45 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+), 5 deletions(-)
git-clone.sh +14 -5
index 0d686c3..0580b5a 100755
@@ -210,11 +210,14 @@ if base=$(get_repo_base "$repo"); then
 	then
 		local=yes
 	fi
+elif [ -f "$repo" ] ; then
+	case "$repo" in /*);; *) repo="$PWD/$repo" ; esac
 fi
 
 dir="$2"
 # Try using "humanish" part of source repo if user didn't specify one
-[ -z "$dir" ] && dir=$(echo "$repo" | sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g')
+[ -z "$dir" ] && dir=$(echo "$repo" | sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g') &&
+[ -f "$repo" ] && dir=$(echo "$repo" | sed -e 's|/*\.bundle$||' -e 's|.*/||g')
 [ -e "$dir" ] && die "destination directory '$dir' already exists."
 [ yes = "$bare" ] && unset GIT_WORK_TREE
 [ -n "$GIT_WORK_TREE" ] && [ -e "$GIT_WORK_TREE" ] &&
@@ -364,11 +367,17 @@ yes)
 		fi
 		;;
 	*)
-		case "$upload_pack" in
-		'') git-fetch-pack --all -k $quiet $depth $no_progress "$repo";;
-		*) git-fetch-pack --all -k $quiet "$upload_pack" $depth $no_progress "$repo" ;;
-		esac >"$GIT_DIR/CLONE_HEAD" ||
+		if [ -f "$repo" ] ; then
+			git bundle unbundle "$repo" > "$GIT_DIR/CLONE_HEAD" ||
+			die "unbundle from '$repo' failed."
+		else
+			case "$upload_pack" in
+			'') git-fetch-pack --all -k $quiet $depth $no_progress "$repo";;
+			*) git-fetch-pack --all -k \
+				$quiet "$upload_pack" $depth $no_progress "$repo" ;;
+			esac >"$GIT_DIR/CLONE_HEAD" ||
 			die "fetch-pack from '$repo' failed."
+		fi
 		;;
 	esac
 	;;
t/t5701-clone-local.sh +45 -0

55 lines not on this page · raw message

Signature · 1 line
1.5.4.3.221.gf0f3f
#1 lore raw

PATCH v2 1/1 clone: support cloning full bundles

The "humanish" part of a bundle is made removing the ".bundle" suffix.

---
Hi,

changes since v3:

* rewrite "humanish" part to be more readable
as requested by Junio
* Fix a typo in one test

Santi

 git-clone.sh           |   36 +++++++++++++++++++++++++++++-------
 t/t5701-clone-local.sh |   45 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 74 insertions(+), 7 deletions(-)
git-clone.sh +29 -7
index 0d686c3..9ae9646 100755
@@ -210,11 +210,27 @@ if base=$(get_repo_base "$repo"); then
 	then
 		local=yes
 	fi
+elif [ -f "$repo" ] ; then
+	case "$repo" in /*);; *) repo="$PWD/$repo" ; esac
+fi
+
+# Decide the directory name of the new repository
+if test -n "$2"
+then
+	dir="$2"
+else
+	# Derive one from the repository name
+	# Try using "humanish" part of source repo if user didn't specify one
+	if test -f "$repo"
+	then
+		# Cloning from a bundle
+		dir=$(echo "$repo" | sed -e 's|/*\.bundle$||' -e 's|.*/||g')
+	else
+		dir=$(echo "$repo" |
+			sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g')
+	fi
 fi
 
-dir="$2"
-# Try using "humanish" part of source repo if user didn't specify one
-[ -z "$dir" ] && dir=$(echo "$repo" | sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g')
 [ -e "$dir" ] && die "destination directory '$dir' already exists."
 [ yes = "$bare" ] && unset GIT_WORK_TREE
 [ -n "$GIT_WORK_TREE" ] && [ -e "$GIT_WORK_TREE" ] &&
@@ -364,11 +380,17 @@ yes)
 		fi
 		;;
 	*)
-		case "$upload_pack" in
-		'') git-fetch-pack --all -k $quiet $depth $no_progress "$repo";;
-		*) git-fetch-pack --all -k $quiet "$upload_pack" $depth $no_progress "$repo" ;;
-		esac >"$GIT_DIR/CLONE_HEAD" ||
+		if [ -f "$repo" ] ; then
+			git bundle unbundle "$repo" > "$GIT_DIR/CLONE_HEAD" ||
+			die "unbundle from '$repo' failed."
+		else
+			case "$upload_pack" in
+			'') git-fetch-pack --all -k $quiet $depth $no_progress "$repo";;
+			*) git-fetch-pack --all -k \
+				$quiet "$upload_pack" $depth $no_progress "$repo" ;;
+			esac >"$GIT_DIR/CLONE_HEAD" ||
 			die "fetch-pack from '$repo' failed."
+		fi
 		;;
 	esac
 	;;
t/t5701-clone-local.sh +45 -0

55 lines not on this page · raw message

Signature · 1 line
1.5.4.3.393.g5540
#2 lore raw
In reply to Santi Béjar
Quoted 10 lines · Santi Béjar
git-clone.sh +2 -0
index 0d686c3..0580b5a 100755
@@ -210,11 +210,14 @@ if base=$(get_repo_base "$repo"); then
 	then
 		local=yes
 	fi
+elif [ -f "$repo" ] ; then
+	case "$repo" in /*);; *) repo="$PWD/$repo" ; esac

git-clone.sh if base=$(get_repo_base "$repo"); then · line 223

Quoted 10 lines
git-clone.sh +2 -1
 fi
 
 dir="$2"
 # Try using "humanish" part of source repo if user didn't specify one
-[ -z "$dir" ] && dir=$(echo "$repo" | sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g')
+[ -z "$dir" ] && dir=$(echo "$repo" | sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g') &&
+[ -f "$repo" ] && dir=$(echo "$repo" | sed -e 's|/*\.bundle$||' -e 's|.*/||g')
 [ -e "$dir" ] && die "destination directory '$dir' already exists."
 [ yes = "$bare" ] && unset GIT_WORK_TREE
 [ -n "$GIT_WORK_TREE" ] && [ -e "$GIT_WORK_TREE" ] &&

This sequence was terse, to the point and very readable when the logic was simpler, but now it is getting out of hand. I think it is a time for rewriting to something more verbose, like...

	# Decide the directory name of the new repository
        if test -n "$2"
        then
        	dir="$2"
	else
        	# Derive one from the repository name
                if test -f "$repo"
                then
                        # Cloning from a bundle
                        dir=... humanish ...
                else
                        dir=... humanish ...
                fi
        fi