threads / patch / 26822

patch, 2 partsgit-submodule.sh: Handle submodules with merge conflicts

Subject: [PATCH 1/2] git-submodule.sh: Handle submodules with merge conflicts

## tl;dr

4 messages between Mar 22, 2011 and Mar 24, 2011. Diffs are folded; open one to read it.

replies: 3people: 3as markdown or json

Nicolas Morey-Chaisemartin· Mar 22, 2011, 08:56 UTC · lore
During a merge with conflict on a submodule, the submodule appears 3 times in git ls-files (stage 1,2,3) which caused the submodule to be used 3 times in git submodule init, sync, update and status command.
This patch filters the results of git ls-files to generate a single entry for conflicting submodules with a 0 SHA1 and 'U' as stage.
After this patch:
- init and sync behave as previously but only once per submodule
- update skips submodule with merge conflicts
- status now display a null SHA1 prefixed by 'U' for submodule with merge conflicts
Signed-off-by: Nicolas Morey-Chaisemartin <nicolas@morey-chaisemartin.com>
---
 git-submodule.sh |   29 ++++++++++++++++++++++++++++-
 1 files changed, 28 insertions(+), 1 deletions(-)
Show changes to git-submodule.sh +28 −1
diff --git a/git-submodule.sh b/git-submodule.sh
index 3a13397..7f6b3cf 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -72,7 +72,24 @@ resolve_relative_url ()
 #
 module_list()
 {
-	git ls-files --error-unmatch --stage -- "$@" | sane_grep '^160000 '
+	git ls-files --error-unmatch --stage -- "$@" |
+	perl -e '
+	my %unmerged = ();
+	my ($null_sha1) = ("0" x 40);
+	while (<STDIN>) {
+		chomp;
+		my ($mode, $sha1, $stage, $path) =
+			/^([0-7]+) ([0-9a-f]{40}) ([0-3])\t(.*)$/;
+		next unless $mode eq "160000";
+		if ($stage ne "0") {
+			if (!$unmerged{$path}++) {
+				print "$mode $null_sha1 U\t$path\n";
+			}
+			next;
+		}
+		print "$_\n";
+	}
+	'
 }
 
 #
@@ -427,6 +444,11 @@ cmd_update()
 	module_list "$@" |
 	while read mode sha1 stage path
 	do
+		if test "$stage" = U
+		then
+			echo >&2 "Skipping unmerged submodule $path"
+			continue
+		fi
 		name=$(module_name "$path") || exit
 		url=$(git config submodule."$name".url)
 		update_module=$(git config submodule."$name".update)
@@ -770,6 +792,11 @@ cmd_status()
 		name=$(module_name "$path") || exit
 		url=$(git config submodule."$name".url)
 		displaypath="$prefix$path"
+		if test "$stage" = U
+		then
+			say "U$sha1 $displaypath"
+			continue
+		fi
 		if test -z "$url" || ! test -d "$path"/.git -o -f "$path"/.git
 		then
 			say "-$sha1 $displaypath"
-- 
1.7.4
Jens Lehmann· Mar 22, 2011, 19:22 UTC · re: Nicolas Morey-Chaisemartin · lore

Re: [PATCH 1/2] git-submodule.sh: Handle submodules with merge conflicts

Thanks, that fixes it nicely!
Am 22.03.2011 09:56, schrieb Nicolas Morey-Chaisemartin:
> During a merge with conflict on a submodule, the submodule appears 3 times in git ls-files (stage 1,2,3) which caused the submodule to be used 3 times in git submodule init, sync, update and status command.
> This patch filters the results of git ls-files to generate a single entry for conflicting submodules with a 0 SHA1 and 'U' as stage.
Nit: Usually we wrap commit messages at about 72 characters.
> After this patch:
> - init and sync behave as previously but only once per submodule
> - update skips submodule with merge conflicts
> - status now display a null SHA1 prefixed by 'U' for submodule with merge conflicts
A test case would be nice (t7405 looks like the right spot for one).
Junio C Hamano· Mar 22, 2011, 21:41 UTC · re: Jens Lehmann · lore

Re: [PATCH 1/2] git-submodule.sh: Handle submodules with merge conflicts

Jens Lehmann <Jens.Lehmann@web.de> writes:
Show 7 quoted lines
> Thanks, that fixes it nicely!
>
> Am 22.03.2011 09:56, schrieb Nicolas Morey-Chaisemartin:
>> During a merge with conflict on a submodule, the submodule appears 3 times in git ls-files (stage 1,2,3) which caused the submodule to be used 3 times in git submodule init, sync, update and status command.
>> This patch filters the results of git ls-files to generate a single entry for conflicting submodules with a 0 SHA1 and 'U' as stage.
>
> Nit: Usually we wrap commit messages at about 72 characters.

Also it is very dissapointing to see that none of the careful thinking that was needed while deciding what each subcommand should do was copied from <7vhbb1320t.fsf@alter.siamese.dyndns.org> -- did I just waste my time trying to guide this topic forward?

Show 6 quoted lines
>> After this patch:
>> - init and sync behave as previously but only once per submodule
>> - update skips submodule with merge conflicts
>> - status now display a null SHA1 prefixed by 'U' for submodule with merge conflicts
>
> A test case would be nice (t7405 looks like the right spot for one).
Nicolas Morey-Chaisemartin· Mar 24, 2011, 06:58 UTC · re: Junio C Hamano · lore

Re: [PATCH 1/2] git-submodule.sh: Handle submodules with merge conflicts

On 03/22/2011 10:41 PM, Junio C Hamano wrote:
Show 13 quoted lines
> Jens Lehmann <Jens.Lehmann@web.de> writes:
>
>> Thanks, that fixes it nicely!
>>
>> Am 22.03.2011 09:56, schrieb Nicolas Morey-Chaisemartin:
>>> During a merge with conflict on a submodule, the submodule appears 3 times in git ls-files (stage 1,2,3) which caused the submodule to be used 3 times in git submodule init, sync, update and status command.
>>> This patch filters the results of git ls-files to generate a single entry for conflicting submodules with a 0 SHA1 and 'U' as stage.
>> Nit: Usually we wrap commit messages at about 72 characters.
> Also it is very dissapointing to see that none of the careful thinking
> that was needed while deciding what each subcommand should do was copied
> from <7vhbb1320t.fsf@alter.siamese.dyndns.org> -- did I just waste my
> time trying to guide this topic forward?
>

Sorry about that. I wasn't sure how much details you put in commit logs. I guess it wasn't enough. I'll fix this as soon as I have added a test case for the 'U' status

← back to recent threads