[RFC] git-clone: add --track <headname> support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add support for a simplified workflow where users
want to clone and start working on a head that is
different from the HEAD of the repository.

Calling

   git-clone --track maint <repo>

Is equivalent to

   git-clone <repo> mydir
   cd mydir
   git-checkout --track -b maint origin/maint

--

Not sure if Junio wants this, but if I am going to migrate
away from cogito, I'd like these common operations to be
dead simple. 

This is something cogito supports using the <repo>#branchname
syntax. I am pretty sure git supports it when fetching
but alas, no longer for cloning. 

And if we want it, there are 2 things I'd ask review for

 - The --track parameter handling - I merely copied the 
   handling for other parameters. Clearly shell doesn't
   do this very elegantly, or at least we don't. 

 - The block that defines head_points_at (@360-370) looks 
   very brittle so I didn't want to mess with it. 

---
 git-clone.sh |   39 +++++++++++++++++++++++++++------------
 1 files changed, 27 insertions(+), 12 deletions(-)

diff --git a/git-clone.sh b/git-clone.sh
index e98e064..c7b3e99 100755
--- a/git-clone.sh
+++ b/git-clone.sh
@@ -14,7 +14,7 @@ die() {
 }
 
 usage() {
-	die "Usage: $0 [--template=<template_directory>] [--reference <reference-repo>] [--bare] [-l [-s]] [-q] [-u <upload-pack>] [--origin <name>] [--depth <n>] [-n] <repo> [<dir>]"
+	die "Usage: $0 [--template=<template_directory>] [--reference <reference-repo>] [--bare] [-l [-s]] [-q] [-u <upload-pack>] [--origin <name>] [--track <head>] [--depth <n>] [-n] <repo> [<dir>]"
 }
 
 get_repo_base() {
@@ -85,6 +85,7 @@ bare=
 reference=
 origin=
 origin_override=
+track=
 use_separate_remote=t
 depth=
 no_progress=
@@ -105,6 +106,11 @@ while
 		shift; template="--template=$1" ;;
 	*,--template=*)
 	  template="$1" ;;
+	1,--track) usage ;;
+	*,--track)
+		shift; track="$1" ;;
+	*,--track=*)
+	  track="$1" ;;
 	*,-q|*,--quiet) quiet=-q ;;
 	*,--use-separate-remote) ;;
 	*,--no-separate-remote)
@@ -344,17 +350,22 @@ if test -z "$bare" && test -f "$GIT_DIR/REMOTE_HEAD"
 then
 	# a non-bare repository is always in separate-remote layout
 	remote_top="refs/remotes/$origin"
-	head_sha1=`cat "$GIT_DIR/REMOTE_HEAD"`
-	case "$head_sha1" in
-	'ref: refs/'*)
-		# Uh-oh, the remote told us (http transport done against
-		# new style repository with a symref HEAD).
-		# Ideally we should skip the guesswork but for now
-		# opt for minimum change.
-		head_sha1=`expr "z$head_sha1" : 'zref: refs/heads/\(.*\)'`
-		head_sha1=`cat "$GIT_DIR/$remote_top/$head_sha1"`
-		;;
-	esac
+	if test ! -z "$track" && test -f "refs/remotes/$origin/$track"
+	then
+		head_sha1=`cat "refs/remotes/$origin/$track"`
+	else
+		head_sha1=`cat "$GIT_DIR/REMOTE_HEAD"`
+		case "$head_sha1" in
+		'ref: refs/'*)
+			# Uh-oh, the remote told us (http transport done against
+			# new style repository with a symref HEAD).
+			# Ideally we should skip the guesswork but for now
+			# opt for minimum change.
+			head_sha1=`expr "z$head_sha1" : 'zref: refs/heads/\(.*\)'`
+			head_sha1=`cat "$GIT_DIR/$remote_top/$head_sha1"`
+			;;
+		esac
+	fi
 
 	# The name under $remote_top the remote HEAD seems to point at.
 	head_points_at=$(
@@ -376,6 +387,10 @@ then
 		done
 		)
 	)
+	if test -n "$track" && test -f "$GIT_DIR/$remote_top/$track"
+	then
+		head_points_at="$track"
+	fi
 
 	# Write out remote.$origin config, and update our "$head_points_at".
 	case "$head_points_at" in
-- 
1.5.1.106.ga32037

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]