git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v4] submodule: add +<branch> syntax for track to allow automatic pulling.

From
FFFabian Franz <git@fabian-franz.de>
Date
Jan 10, 2009, 02:10 UTC
Message-ID
<1231553410-7541-4-git-send-email-git@fabian-franz.de>
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
Previous: Fabian FranzNext: Fabian Franz
Message 4 of 9 in “submodule: allow tracking of the newest revision of a branch in a submodule”
  1. submodule: allow tracking of the newest revision of a branch in a submoduleFabian Franz, Jan 10, 2009
  2. submodule: add --no-fetch parameter to update commandFabian Franz, Jan 10, 2009
  3. submodule: add --use-gitmodules parameter to update commandFabian Franz, Jan 10, 2009
  4. submodule: add +<branch> syntax for track to allow automatic pulling.Fabian Franz, Jan 10, 2009
  5. submodule: add --recursive parameter to update commandFabian Franz, Jan 10, 2009
  6. Junio C HamanoJan 11, 2009
  7. Nanako ShiraishiJan 11, 2009
  8. Nanako ShiraishiJan 11, 2009
  9. Johannes SchindelinJan 10, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.