git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Fabian Franz <git@fabian-franz.de>
To: git@vger.kernel.org
Cc: j.sixt@viscovery.net, hjemli@gmail.com, gitster@pobox.com,
	Fabian Franz <git@fabian-franz.de>
Subject: [PATCH v4] submodule: add +<branch> syntax for track to allow automatic pulling.
Date: Sat, 10 Jan 2009 00:10:09 -0200	[thread overview]
Message-ID: <1231553410-7541-4-git-send-email-git@fabian-franz.de> (raw)
In-Reply-To: <1231553410-7541-3-git-send-email-git@fabian-franz.de>

When the track parameter is set to +<branch>, on update command a
new branch is created tracking the remote branch (if it does not
yet exist). Then the branch is checked out and git-pull is run.

Signed-off-by: Fabian Franz <git@fabian-franz.de>
---
 Documentation/git-submodule.txt |    3 +++
 git-submodule.sh                |   26 ++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt
index 175b4b5..fbb18ee 100644
--- a/Documentation/git-submodule.txt
+++ b/Documentation/git-submodule.txt
@@ -166,6 +166,9 @@ OPTIONS
 -t::
 --track::
 	Branch/Tag/HEAD (pathspec) of repository to track in a submodule.
+	If you give +<branch> as parameter, a new branch will be created and
+	setup to track the remote branch. Then on update git-pull is used to
+	update the branch.
 
 --cached::
 	This option is only valid for status and summary commands.  These
diff --git a/git-submodule.sh b/git-submodule.sh
index 81b96dd..54b59b2 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -372,6 +372,32 @@ cmd_update()
 			die "Unable to find current revision in submodule path '$path'"
 		fi
 
+		pull=
+		case "$track" in
+			"+"*)
+				pull=1
+				track=${track#+}
+			;;
+		esac
+
+		if test -n "$pull"
+		then
+			say "Pulling updates for branch '$track' for submodule path '$path'"
+			origin=$(unset GIT_DIR; cd "$path" &&
+				get_default_remote) ||
+			die "Unable to get default remote destination in submodule path '$path'."
+			(unset GIT_DIR; cd "$path" &&
+				git-rev-parse --verify --quiet "refs/heads/$track" >/dev/null || 
+				git-branch --track "$track" "$origin/$track") || 
+			die "Unable to create branch '$track' in submodule path '$path'"
+
+			(unset GIT_DIR; cd "$path" &&
+				git-checkout -q "$track" &&
+				git-pull ${quiet:+-q}) ||
+			die "Unable to pull for branch '$track' in submodule path '$path'"
+			sha1="$track"
+		fi
+
 		if test "$subsha1" != "$sha1"
 		then
 			force=
-- 
1.5.3.6

  reply	other threads:[~2009-01-10  2:27 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-10  2:10 [PATCH v4] submodule: allow tracking of the newest revision of a branch in a submodule Fabian Franz
2009-01-10  2:10 ` [PATCH v4] submodule: add --no-fetch parameter to update command Fabian Franz
2009-01-10  2:10   ` [PATCH v4] submodule: add --use-gitmodules " Fabian Franz
2009-01-10  2:10     ` Fabian Franz [this message]
2009-01-10  2:10       ` [PATCH v4] submodule: add --recursive " Fabian Franz
2009-01-11  1:34       ` [PATCH v4] submodule: add +<branch> syntax for track to allow automatic pulling Junio C Hamano
2009-01-10 14:23 ` [PATCH v4] submodule: allow tracking of the newest revision of a branch in a submodule Johannes Schindelin
2009-01-11  1:31 ` [PATCH v4] submodule: add --no-fetch parameter to update command Nanako Shiraishi
2009-01-11  1:32 ` Nanako Shiraishi

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=1231553410-7541-4-git-send-email-git@fabian-franz.de \
    --to=git@fabian-franz.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=hjemli@gmail.com \
    --cc=j.sixt@viscovery.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).