git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Soria Parra <sn_@gmx.net>
To: git@vger.kernel.org
Cc: David Soria Parra <dsp@php.net>
Subject: [PATCH v2 1/2] Teach clone to clone just one remote branch using --track
Date: Tue,  1 Dec 2009 23:51:04 +0100	[thread overview]
Message-ID: <1259707865-6561-2-git-send-email-sn_@gmx.net> (raw)
In-Reply-To: <1259707865-6561-1-git-send-email-sn_@gmx.net>

From: David Soria Parra <dsp@php.net>

Add a --track option that can be used to clone just the
given branch from the remote and nothing else. This is done
by setting the remote.<branch>.fetch option before cloning.
This option cannot be used together with --mirror.
For example using

    git clone --track next git://git.kernel.org/pub/scm/git/git.git

will just clone the next branch from the git.git repository.

The option is called --track to ensure clean wording with
'git remote add --track'.

Signed-off-by: David Soria Parra <dsp@php.net>
---
 builtin-clone.c        |   12 +++++++++++-
 t/t5708-clone-track.sh |   43 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 1 deletions(-)
 create mode 100755 t/t5708-clone-track.sh

diff --git a/builtin-clone.c b/builtin-clone.c
index 5df8b0f..bc335ee 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -43,6 +43,7 @@ static char *option_template, *option_reference, *option_depth;
 static char *option_origin = NULL;
 static char *option_branch = NULL;
 static char *option_upload_pack = "git-upload-pack";
+static char *option_track = NULL;
 static int option_verbose;
 
 static struct option builtin_clone_options[] = {
@@ -76,6 +77,8 @@ static struct option builtin_clone_options[] = {
 		   "path to git-upload-pack on the remote"),
 	OPT_STRING(0, "depth", &option_depth, "depth",
 		    "create a shallow clone of that depth"),
+	OPT_STRING('t', "track", &option_track, "branch",
+			"remote branche to track"),
 
 	OPT_END()
 };
@@ -483,7 +486,14 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 		strbuf_addf(&branch_top, "refs/remotes/%s/", option_origin);
 	}
 
-	strbuf_addf(&value, "+%s*:%s*", src_ref_prefix, branch_top.buf);
+	if (option_track) {
+		if (option_mirror)
+			return error("Cannot use --track together with --mirror");
+		strbuf_addf(&value, "+%s%s:%s%s", src_ref_prefix, option_track, branch_top.buf, option_track);
+		option_branch = option_track;
+	} else {
+		strbuf_addf(&value, "+%s*:%s*", src_ref_prefix, branch_top.buf);
+	}
 
 	if (option_mirror || !option_bare) {
 		/* Configure the remote */
diff --git a/t/t5708-clone-track.sh b/t/t5708-clone-track.sh
new file mode 100755
index 0000000..71b8461
--- /dev/null
+++ b/t/t5708-clone-track.sh
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+test_description='clone --track option'
+. ./test-lib.sh
+
+check_HEAD() {
+	echo refs/heads/"$1" >expect &&
+	git symbolic-ref HEAD >actual &&
+	test_cmp expect actual
+}
+
+check_file() {
+	echo "$1" >expect &&
+	test_cmp expect file
+}
+
+test_expect_success 'setup' '
+	mkdir parent &&
+	(cd parent && git init &&
+	 echo one >file && git add file && git commit -m one &&
+	 git checkout -b two &&
+	 echo two >file && git add file && git commit -m two &&
+	 git checkout master)
+'
+
+test_expect_success 'vanilla clone has both branches' '
+	git clone parent clone &&
+	(cd clone &&
+	git branch -r | grep master &&
+	git branch -r | grep two
+	)
+'
+
+test_expect_success 'clone -t chooses specified remote branch' '
+	git clone -t two parent clone-two &&
+	(cd clone-two &&
+	!(git branch -r | grep master) &&
+	git branch -r | grep two &&
+	check_HEAD two
+	)
+'
+
+test_done
-- 
1.6.6.rc0.268.g1c272

  reply	other threads:[~2009-12-01 22:51 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-01 22:51 [PATCH v2] Add --track option to git clone David Soria Parra
2009-12-01 22:51 ` David Soria Parra [this message]
2009-12-01 22:51 ` [PATCH v2 2/2] Documentation: Add --track option to the git clone manpage David Soria Parra
2009-12-02  2:08 ` [PATCH v2] Add --track option to git clone Sean Estabrooks
2009-12-02  7:20   ` David Soria Parra
2009-12-02 10:20 ` Nanako Shiraishi
2009-12-02 10:33   ` David Soria Parra
2009-12-02 19:08   ` Jeff King
2009-12-02 19:27     ` David Soria Parra
2009-12-02 21:07     ` Nanako Shiraishi
2009-12-02 22:37       ` Jeff King
2009-12-02 23:02         ` Junio C Hamano
2009-12-03  5:31     ` Björn Steinbrink

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=1259707865-6561-2-git-send-email-sn_@gmx.net \
    --to=sn_@gmx.net \
    --cc=dsp@php.net \
    --cc=git@vger.kernel.org \
    /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).