git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Spencer E. Olson" <olsonse@umich.edu>
To: git@vger.kernel.org
Cc: "Spencer E. Olson" <olsonse@umich.edu>
Subject: [PATCH] submodule: no [--merge|--rebase] when newly cloned
Date: Wed, 16 Feb 2011 05:46:57 -0700	[thread overview]
Message-ID: <1297860417-21895-1-git-send-email-olsonse@umich.edu> (raw)

Previously, when a submodule was cloned in the same command execution, --rebase
or --merge would attempt to run (instead of and) before a checkout, resulting in
an empty working directory.  This patch ignores --rebase or --merge for a
particular submodule when that submodule is newly cloned and instead simply
checks out the appropriate revision.

Signed-off-by: Spencer E. Olson <olsonse@umich.edu>
---
 git-submodule.sh |   28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/git-submodule.sh b/git-submodule.sh
index 8b90589..44d8741 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -365,6 +365,27 @@ cmd_init()
 }
 
 #
+# Test whether an element of the $3(=IFS) separated list $2 matches $1
+#
+str_contains()
+{
+	if test -n "$3"
+	then
+		local IFS="$3"
+	fi
+	for i in $2
+	do
+		if test "$i" = "$1"
+		then
+			echo "yes"
+			return
+		fi
+	done
+	echo "no"
+	return
+}
+
+#
 # Update each submodule path to correct revision, using clone and checkout as needed
 #
 # $@ = requested paths (default to all)
@@ -423,6 +444,7 @@ cmd_update()
 		cmd_init "--" "$@" || return
 	fi
 
+	cloned_modules=
 	module_list "$@" |
 	while read mode sha1 stage path
 	do
@@ -442,6 +464,7 @@ cmd_update()
 		if ! test -d "$path"/.git -o -f "$path"/.git
 		then
 			module_clone "$path" "$url" "$reference"|| exit
+			cloned_modules="$cloned_modules;$name"
 			subsha1=
 		else
 			subsha1=$(clear_local_git_env; cd "$path" &&
@@ -469,6 +492,11 @@ cmd_update()
 				die "Unable to fetch in submodule path '$path'"
 			fi
 
+			if test "$(str_contains "$name" "$cloned_modules" '\;')" = "yes"
+			then
+				update_module=
+			fi
+
 			case "$update_module" in
 			rebase)
 				command="git rebase"
-- 
1.7.4.1.42.g43f9f

             reply	other threads:[~2011-02-16 12:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-16 12:46 Spencer E. Olson [this message]
2011-02-16 19:51 ` [PATCH] submodule: no [--merge|--rebase] when newly cloned Junio C Hamano
2011-02-16 20:10   ` Jens Lehmann
2011-02-16 21:41     ` Junio C Hamano
2011-02-17  0:21       ` Spencer E. Olson
2011-02-17  7:10   ` Johannes Sixt
2011-02-18  0:34     ` Martin von Zweigbergk
2011-02-18  0:48       ` Spencer E. Olson
2011-02-18  0:59         ` Martin von Zweigbergk

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1297860417-21895-1-git-send-email-olsonse@umich.edu \
    --to=olsonse@umich.edu \
    --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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).