From: Martin Langhoff <martin@catalyst.net.nz>
To: git@vger.kernel.org, junkio@cox.net
Cc: Martin Langhoff <martin@catalyst.net.nz>
Subject: [RFC] git-clone: add --track <headname> support
Date: Thu, 12 Apr 2007 22:08:59 +1200 [thread overview]
Message-ID: <1176372539871-git-send-email-martin@catalyst.net.nz> (raw)
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
next reply other threads:[~2007-04-12 10:09 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-12 10:08 Martin Langhoff [this message]
2007-04-12 10:23 ` [RFC] git-clone: add --track <headname> support Junio C Hamano
2007-04-12 21:32 ` Martin Langhoff
2007-04-12 16:34 ` Carl Worth
2007-04-12 21:46 ` Martin Langhoff
2007-04-12 23:24 ` Carl Worth
2007-04-12 23:50 ` Martin Langhoff
2007-04-13 0:28 ` Junio C Hamano
2007-04-13 3:50 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1176372539871-git-send-email-martin@catalyst.net.nz \
--to=martin@catalyst.net.nz \
--cc=git@vger.kernel.org \
--cc=junkio@cox.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).