Skip to contentSkip to conversation

Make cg-clone handle local directories as sources

PATCH In review Ryan Anderson 1 participant 3 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Make cg-clone handle local directories as sources

cg-clone is described as only being used with remote repositories, but it has the nice feature of creating the destination directory for you.

This patch adds two features:
1. A destination directory can (optionally) be specified.
2. The source directory can be in the local file system.

The following, for example, now works:

	cg-clone rsync://rsync.kernel.org/pub/scm/cogito/cogito.git
	mkdir test ; cd test
	cg-clone ../cogito ../cogito2/
cg-clone (mode:100755) renamed from cg-clone (mode:100755 sha1:4ee0685c358e094c5350b3968d013105da6ddf7e) +12 -3
Index: cg-clone
===================================================================
@@ -11,13 +11,22 @@
 . cg-Xlib
 
 location=$1
-[ "$location" ] || die "usage: cg-clone SOURCE_LOC"
+[ "$location" ] || die "usage: cg-clone SOURCE_LOC [DEST_LOC]"
 location=${location%/}
 
-dir=${location##*/}; dir=${dir%.git}
+if [ "$2" == "" ]; then
+	dir=${location##*/}; dir=${dir%.git}
+else
+	dir=$2
+fi
+
+pwd=$(pwd)
+relative_location=$(echo "$location" | sed -e "s#^[^/]#$pwd\/&#")
+
 [ -e "$dir" ] && die "$dir/ already exists"
 mkdir "$dir"
 cd "$dir"
 
-cg-init $location || exit $?
+echo "cg-init $relative_location"
+cg-init $relative_location || exit $?
 echo "Cloned to $dir/ (origin $location available as branch \"origin\")"
Signature · 2 lines
Ryan Anderson
  sometimes Pug Majere
#1 lore raw

Ignore this, I did something stupid - new patch to follow in a minute.

Quoted 55 lines · Ryan Anderson

cg-clone is described as only being used with remote repositories, but it has the nice feature of creating the destination directory for you.

This patch adds two features:
1. A destination directory can (optionally) be specified.
2. The source directory can be in the local file system.

The following, for example, now works:

	cg-clone rsync://rsync.kernel.org/pub/scm/cogito/cogito.git
	mkdir test ; cd test
	cg-clone ../cogito ../cogito2/

Index: cg-clone
===================================================================

cg-clone (mode:100755) renamed from cg-clone (mode:100755 sha1:4ee0685c358e094c5350b3968d013105da6ddf7e) +12 -3
@@ -11,13 +11,22 @@
 . cg-Xlib
 
 location=$1
-[ "$location" ] || die "usage: cg-clone SOURCE_LOC"
+[ "$location" ] || die "usage: cg-clone SOURCE_LOC [DEST_LOC]"
 location=${location%/}
 
-dir=${location##*/}; dir=${dir%.git}
+if [ "$2" == "" ]; then
+	dir=${location##*/}; dir=${dir%.git}
+else
+	dir=$2
+fi
+
+pwd=$(pwd)
+relative_location=$(echo "$location" | sed -e "s#^[^/]#$pwd\/&#")
+
 [ -e "$dir" ] && die "$dir/ already exists"
 mkdir "$dir"
 cd "$dir"
 
-cg-init $location || exit $?
+echo "cg-init $relative_location"
+cg-init $relative_location || exit $?
 echo "Cloned to $dir/ (origin $location available as branch \"origin\")"
Signature · 8 lines
-- 

Ryan Anderson
  sometimes Pug Majere
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Ryan Anderson
  sometimes Pug Majere
#2 lore raw
In reply to Ryan Anderson

cg-clone is described as only being used with remote repositories, but it has the nice feature of creating the destination directory for you.

This patch adds two features:
1. A destination directory can (optionally) be specified.
2. The source directory can be in the local file system.

The following, for example, now works:

cg-clone rsync://rsync.kernel.org/pub/scm/cogito/cogito.git mkdir test ; cd test
cg-clone ../cogito ../cogito2/

(This version of the patch actually doesn't break existing functionality.)

cg-clone (mode:100755 sha1:e42237e0408bc3f34cc70a956c29df1251bd1571) renamed from cg-clone (mode:100755 sha1:4ee0685c358e094c5350b3968d013105da6ddf7e) +15 -3
Index: cg-clone
===================================================================
@@ -11,13 +11,25 @@
 . cg-Xlib
 
 location=$1
-[ "$location" ] || die "usage: cg-clone SOURCE_LOC"
+[ "$location" ] || die "usage: cg-clone SOURCE_LOC [DEST_LOC]"
 location=${location%/}
 
-dir=${location##*/}; dir=${dir%.git}
+if [ "$2" == "" ]; then
+	dir=${location##*/}; dir=${dir%.git}
+else
+	dir=$2
+fi
+
+pwd=$(pwd)
+if ! echo "$location" | grep -q ":" ; then
+	relative_location=$(echo "$location" | sed -e "s#^[^/]#$pwd\/&#")
+else
+	relative_location="$location"
+fi
+
 [ -e "$dir" ] && die "$dir/ already exists"
 mkdir "$dir"
 cd "$dir"
 
-cg-init $location || exit $?
+cg-init "$relative_location" || exit $?
 echo "Cloned to $dir/ (origin $location available as branch \"origin\")"