From: Martin Langhoff Date: Thu, 12 Apr 2007 10:08:59 GMT Subject: [RFC] git-clone: add --track support Message-ID: <1176372539871-git-send-email-martin@catalyst.net.nz> 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 Is equivalent to git-clone 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 #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=] [--reference ] [--bare] [-l [-s]] [-q] [-u ] [--origin ] [--depth ] [-n] []" + die "Usage: $0 [--template=] [--reference ] [--bare] [-l [-s]] [-q] [-u ] [--origin ] [--track ] [--depth ] [-n] []" } 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