Skip to contentSkip to conversation

submodule: no [--merge|--rebase] when newly cloned

PATCH In review Spencer E. Olson 3 participants 11 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 submodule: no [--merge|--rebase] when newly cloned

Previously, when a new submodule is cloned by running "git submodule update [--merge|--rebase]", the newly cloned submodule does not get checked out and a rebase or merge is incorrectly attempted against an empty working directory. This patch ignores --rebase or --merge for new submodules and instead simply checks out the appropriate revision.

---
 git-submodule.sh |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)
git-submodule.sh +21 -0
index 8b90589..7724885 100755
@@ -365,6 +365,19 @@ cmd_init()
 }
 
 #
+# Test whether an element of the ';' separated list $2 matches $1
+#
+list_contains()
+{
+	case "$2;" in
+	*";$1;"*)
+		: yes ;;
+	*)
+		! : no ;;
+	esac
+}
+
+#
 # Update each submodule path to correct revision, using clone and checkout as needed
 #
 # $@ = requested paths (default to all)
@@ -423,6 +436,7 @@ cmd_update()
 		cmd_init "--" "$@" || return
 	fi
 
+	cloned_modules=
 	module_list "$@" |
 	while read mode sha1 stage path
 	do
@@ -442,6 +456,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 +484,12 @@ cmd_update()
 				die "Unable to fetch in submodule path '$path'"
 			fi
 
+			list_contains "$name" "$cloned_modules"
+			if test "$?" = 0
+			then
+				update_module=
+			fi
+
 			case "$update_module" in
 			rebase)
 				command="git rebase"
Signature · 1 line
1.7.4.1.42.g43f9f
#1 lore raw

PATCH 2/2 t7406: "git submodule update {--merge|--rebase]" with new submodules

This patch adds two new test cases in t7406 to ensure that the --merge/--rebase options are ignored for "git submodule update" with new modules. These test that a simple checkout is performed instead.

---
 t/t7406-submodule-update.sh |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)
t/t7406-submodule-update.sh +24 -0
index bfb4975..141251c 100755
@@ -203,4 +203,28 @@ test_expect_success 'submodule init picks up merge' '
 	)
 '
 
+test_expect_success 'submodule update --merge  - ignores --merge  for new submodules' '
+	(cd super &&
+	 rm -rf submodule &&
+	 git submodule update submodule &&
+	 git submodule status submodule >expect &&
+	 rm -rf submodule &&
+	 git submodule update --merge submodule &&
+	 git submodule status submodule >actual &&
+	 test_cmp expect actual
+	)
+'
+
+test_expect_success 'submodule update --rebase - ignores --rebase for new submodules' '
+	(cd super &&
+	 rm -rf submodule &&
+	 git submodule update submodule &&
+	 git submodule status submodule >expect &&
+	 rm -rf submodule &&
+	 git submodule update --rebase submodule &&
+	 git submodule status submodule >actual &&
+	 test_cmp expect actual
+	)
+'
+
 test_done
Signature · 1 line
1.7.4.1.42.g43f9f
Acked-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2 (v2)] t7406: "git submodule update {--merge|--rebase]" with new submodules

Am 17.02.2011 17:18, schrieb Spencer E. Olson:

Quoted 32 lines

This patch adds two new test cases in t7406 to ensure that the --merge/--rebase options are ignored for "git submodule update" with new modules. These test that a simple checkout is performed instead.

---
 t/t7406-submodule-update.sh |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)
t/t7406-submodule-update.sh +15 -0
index bfb4975..141251c 100755
@@ -203,4 +203,28 @@ test_expect_success 'submodule init picks up merge' '
 	)
 '
 
+test_expect_success 'submodule update --merge  - ignores --merge  for new submodules' '
+	(cd super &&
+	 rm -rf submodule &&
+	 git submodule update submodule &&
+	 git submodule status submodule >expect &&
+	 rm -rf submodule &&
+	 git submodule update --merge submodule &&
+	 git submodule status submodule >actual &&
+	 test_cmp expect actual
+	)
+'
+
+test_expect_success 'submodule update --rebase - ignores --rebase for new submodules' '
+	(cd super &&
+	 rm -rf submodule &&

t/t7406-submodule-update.sh test_expect_success 'submodule init picks up merge' ' · line 230

Quoted 10 lines
t/t7406-submodule-update.sh +9 -0
+	 git submodule update submodule &&
+	 git submodule status submodule >expect &&
+	 rm -rf submodule &&
+	 git submodule update --rebase submodule &&
+	 git submodule status submodule >actual &&
+	 test_cmp expect actual
+	)
+'
+
 test_done

Thanks for writing these tests!

Unfortunately the first new test doesn't fail for me with current git. This should be fixed to be able to detect regressions in the future, so I came up with replacing the "git submodule status submodule" calls with "git status -s submodule", which did the trick for me.

Apart from that tests which cover the case when rebase or merge are configured via "submodule.<name>.update" would help, as that triggers the same problem.

So maybe you want to squash the following diff in, then feel free to add:

t/t7406-submodule-update.sh +32 -4
index 141251c..fa9d23a 100755
@@ -207,10 +207,10 @@ test_expect_success 'submodule update --merge  - ignores --merge  for new submod
 	(cd super &&
 	 rm -rf submodule &&
 	 git submodule update submodule &&
-	 git submodule status submodule >expect &&
+	 git status -s submodule >expect &&
 	 rm -rf submodule &&
 	 git submodule update --merge submodule &&
-	 git submodule status submodule >actual &&
+	 git status -s submodule >actual &&
 	 test_cmp expect actual
 	)
 '
@@ -219,10 +219,38 @@ test_expect_success 'submodule update --rebase - ignores --rebase for new submod
 	(cd super &&
 	 rm -rf submodule &&
 	 git submodule update submodule &&
-	 git submodule status submodule >expect &&
+	 git status -s submodule >expect &&
 	 rm -rf submodule &&
 	 git submodule update --rebase submodule &&
-	 git submodule status submodule >actual &&
+	 git status -s submodule >actual &&
+	 test_cmp expect actual
+	)
+'
+
+test_expect_success 'submodule update ignores update=merge config for new submodules' '
+	(cd super &&
+	 rm -rf submodule &&
+	 git submodule update submodule &&
+	 git status -s submodule >expect &&
+	 rm -rf submodule &&
+	 git config submodule.submodule.update merge &&
+	 git submodule update submodule &&
+	 git status -s submodule >actual &&
+	 git config --unset submodule.submodule.update &&
+	 test_cmp expect actual
+	)
+'
+
+test_expect_success 'submodule update ignores update=rebase config for new submodules' '
+	(cd super &&
+	 rm -rf submodule &&
+	 git submodule update submodule &&
+	 git status -s submodule >expect &&
+	 rm -rf submodule &&
+	 git config submodule.submodule.update rebase &&
+	 git submodule update submodule &&
+	 git status -s submodule >actual &&
+	 git config --unset submodule.submodule.update &&
 	 test_cmp expect actual
 	)
 '
Signature · 1 line
1.7.4.1.109.g3d8f5
#3 lore raw

Re: [PATCH 2/2 (v2)] t7406: "git submodule update {--merge|--rebase]" with new submodules

Quoted 3 lines · Jens Lehmann

This should be fixed to be able to detect regressions in the future, so I came up with replacing the "git submodule status submodule" calls with "git status -s submodule", which did the trick for me.

Hmph, is that a bug in "git submodule status" or is the subcommand deliberately designed to ignore this class of differences?

#4 lore raw

Re: [PATCH 2/2 (v2)] t7406: "git submodule update {--merge|--rebase]" with new submodules

Am 17.02.2011 21:18, schrieb Junio C Hamano:

Quoted 8 lines
Quoted 3 lines · Jens Lehmann

This should be fixed to be able to detect regressions in the future, so I came up with replacing the "git submodule status submodule" calls with "git status -s submodule", which did the trick for me.

Hmph, is that a bug in "git submodule status" or is the subcommand deliberately designed to ignore this class of differences?

The latter, it doesn't care about working tree modifications inside of submodules as It uses the "--ignore-submodules=dirty" option when calling "git diff-files" (I added that in 18076502). The reason for one test to succeed and the other to fail is that the merge succeeds even though the work tree is empty while rebase errors out. So "git submodule status" is the wrong command to detect work tree differences, that's why we have to use "git status" here.

Acked-by on v1 1/2
#5 lore raw
In reply to Spencer E. Olson

Am 17.02.2011 17:18, schrieb Spencer E. Olson:

Quoted 5 lines

Previously, when a new submodule is cloned by running "git submodule update [--merge|--rebase]", the newly cloned submodule does not get checked out and a rebase or merge is incorrectly attempted against an empty working directory. This patch ignores --rebase or --merge for new submodules and instead simply checks out the appropriate revision.

Nice work, thanks!

Just a small thing: This problem also happens when the configuration "submodule.<name>.update" is set to either "rebase" or "merge", not only when using the command line options. So perhaps you could reword the topic to something like "submodule: don't merge or rebase when newly cloned" and adjust both commit messages a bit?

Apart from that:

Acked-by Jens Lehmann
#6 lore raw
Quoted 7 lines · Jens Lehmann

Am 17.02.2011 17:18, schrieb Spencer E. Olson:

Quoted 5 lines

Previously, when a new submodule is cloned by running "git submodule update [--merge|--rebase]", the newly cloned submodule does not get checked out and a rebase or merge is incorrectly attempted against an empty working directory. This patch ignores --rebase or --merge for new submodules and instead simply checks out the appropriate revision.

Quoted 7 lines

Nice work, thanks!

Just a small thing: This problem also happens when the configuration "submodule.<name>.update" is set to either "rebase" or "merge", not only when using the command line options. So perhaps you could reword the topic to something like "submodule: don't merge or rebase when newly cloned" and adjust both commit messages a bit?

I tentatively queued with this rewrite (the patch text is the same as the one I sent previously).

From: Spencer E. Olson <[email protected]>
Date: Thu, 17 Feb 2011 09:18:45 -0700
Subject: [PATCH] submodule: no [--merge|--rebase] when newly cloned

"git submodule update" can be run with either the "--merge" or "--rebase" option, or submodule.<name>.update configuration variable can be set to "merge" or "rebase, to cause local work to get integrated when updating the submodule.

When a submodule is newly cloned, however, it does not have a check out when a rebase or merge is attempted, leading to a failure. For newly cloned submodules, simply check out the appropriate revision. There is no local work to integrate with for them.

#7 lore raw

This looks fine by me.

What about the testing patch? It'll be a few hours before I can resubmit with "git submodule status submodule" changed to "git status -s submodule".

Quoted 36 lines · Junio C Hamano
Quoted 7 lines · Jens Lehmann

Am 17.02.2011 17:18, schrieb Spencer E. Olson:

Quoted 5 lines

Previously, when a new submodule is cloned by running "git submodule update [--merge|--rebase]", the newly cloned submodule does not get checked out and a rebase or merge is incorrectly attempted against an empty working directory. This patch ignores --rebase or --merge for new submodules and instead simply checks out the appropriate revision.

Quoted 7 lines

Nice work, thanks!

Just a small thing: This problem also happens when the configuration "submodule.<name>.update" is set to either "rebase" or "merge", not only when using the command line options. So perhaps you could reword the topic to something like "submodule: don't merge or rebase when newly cloned" and adjust both commit messages a bit?

I tentatively queued with this rewrite (the patch text is the same as the one I sent previously).

From: Spencer E. Olson <[email protected]>
Date: Thu, 17 Feb 2011 09:18:45 -0700
Subject: [PATCH] submodule: no [--merge|--rebase] when newly cloned

"git submodule update" can be run with either the "--merge" or
"--rebase" option, or submodule.<name>.update configuration variable can be set to "merge" or "rebase, to cause local work to get integrated when updating the submodule.

When a submodule is newly cloned, however, it does not have a check out when a rebase or merge is attempted, leading to a failure. For newly cloned submodules, simply check out the appropriate revision. There is
no local work to integrate with for them.

#8 lore raw
Quoted 4 lines · Spencer E. Olson

This looks fine by me.

What about the testing patch? It'll be a few hours before I can resubmit with "git submodule status submodule" changed to "git status -s submodule".

I just squashed the patch from Jens in, with Ack from him.

#9 lore raw

great, and thanks

Quoted 8 lines · Junio C Hamano
Quoted 5 lines · Spencer E. Olson

This looks fine by me.

What about the testing patch? It'll be a few hours before I can resubmit with "git submodule status submodule" changed to "git status -s submodule".

I just squashed the patch from Jens in, with Ack from him.

#10 lore raw
In reply to Spencer E. Olson

Review cmd_update() · line 492

Quoted 10 lines · Spencer E. Olson
(quoted diff) +6 -0
@@ -469,6 +484,12 @@ cmd_update()
 				die "Unable to fetch in submodule path '$path'"
 			fi
 
+			list_contains "$name" "$cloned_modules"
+			if test "$?" = 0
+			then
+				update_module=
+			fi
+

It would be a lot easier to read if you said this:

if list_contains "$name" "$cloned_modules" then
update_module=
fi

or just open code the idiom:

	case ";list-of-stuff-with-delimiter;" in
        *";i-want-to-see-this;"*) : happy ;;
	esac

without introducing "list_contains" that is called only once.

But otherwise the patch looks good.

Thanks.

-- >8 --
From: Spencer E. Olson <[email protected]>
Date: Thu, 17 Feb 2011 09:18:45 -0700
Subject: [PATCH] submodule: no [--merge|--rebase] when newly cloned

Previously, when a new submodule is cloned by running "git submodule update [--merge|--rebase]", the newly cloned submodule does not get checked out and a rebase or merge is incorrectly attempted against an empty working directory. This patch ignores --rebase or --merge for new submodules and instead simply checks out the appropriate revision.

---
 git-submodule.sh |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
git-submodule.sh +9 -0
index 8b90589..5e989b7 100755
@@ -423,6 +423,7 @@ cmd_update()
 		cmd_init "--" "$@" || return
 	fi
 
+	cloned_modules=
 	module_list "$@" |
 	while read mode sha1 stage path
 	do
@@ -442,6 +443,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 +471,13 @@ cmd_update()
 				die "Unable to fetch in submodule path '$path'"
 			fi
 
+			# Is this something we just cloned?
+			case ";$cloned_modules;" in
+			*";$name;"*)
+				# then there is no local change to integrate
+				update_module= ;;
+			esac
+
 			case "$update_module" in
 			rebase)
 				command="git rebase"
Signature · 1 line
1.7.4.1.107.ga7184