From: Jens Lehmann <Jens.Lehmann@web.de>
To: Junio C Hamano <gitster@pobox.com>
Cc: Kenny Simpson <theonetruekenny@yahoo.com>, git@vger.kernel.org
Subject: Re: git diff across submodules
Date: Thu, 20 Sep 2012 21:51:42 +0200 [thread overview]
Message-ID: <505B73CE.5030009@web.de> (raw)
In-Reply-To: <7v4nmtfxvx.fsf@alter.siamese.dyndns.org>
Am 20.09.2012 00:31, schrieb Junio C Hamano:
> Junio C Hamano <gitster@pobox.com> writes:
>
>> I also suspect that you do not have to change "git diff" at all to
>> show the patch recursively by using the attribute mechanism (look in
>> Documentation/gitattributes.text for a string GIT_EXTERNAL_DIFF).
>> It might be just as simple as doing this:
>>
>> echo >.gitattributes "/lib/frotz diff=subrecurse"
>> git config diff.subrecurse.command $HOME/bin/diff-subrecurse
>> cat >$HOME/bin/diff-subrecurse <<\-EOF
>> #!/bin/sh
>> path=$1 old_hex=$3 new_hex=$6
>> unset GIT_DIR
>> cd "$path" || exit 1
>> git diff "$old_hex" "$new_hex"
>> EOF
>> chmod +x $HOME/bin/diff-subrecurse
>>
>> The corner cases like "new submodule", "removed submodule" are left
>> as an exercise to the reader ;-)
>
> It turns out that essentially the above outline I concocted in my
> MUA is usable almost as-is.
>
> Here is what I ended up with.
>
> * In .git/config of the superproject, I added this:
>
> [diff "submodule-recurse"]
> command = src/bin/diff-submodule-recurse
>
> * In the superproject, src/bin/diff-submodule-recurse has this
> (this is probably whitespace damaged---the lines must be indented
> by HT for the here document to correctly work):
>
> #!/bin/sh
> # $1 $2 $3 $4 $5 $6 $7
> # path old-file old-hex old-mode new-file new-hex new-mode
>
> case "$#,$4,$7" in
> 7,160000,160000) ;;
> *) echo "diff --git a/$1 b/$1"
> echo "(punt)"
> exit
> ;;
> esac
> unset GIT_DIR
> cd "$1" || {
> cat <<-\EOF
> diff --git a/$1 b/$1
> (cannot chdir to $1)
> -Subproject commit $3
> +Subproject commit $6
> EOF
> }
> git --no-pager diff --src-prefix="s/$1/" --dst-prefix="m/$1/" "$3" "$6"
>
> * In .gitattributes of the superproject, I have this:
>
> /var diff=submodule-recurse
>
> The superproject in this case is a repository to control what I have
> in my $HOME directory (e.g. it has src/dot/Makefile that builds and
> installs the appropriate dotfiles, src/bin/Makefile that builds and
> installs to $HOME/bin, etc.), and one subdirectory, 'var', is a
> submodule that is only cloned to some but not all machines I clone
> this superproject to.
>
> With this setting, things like
>
> $ git diff HEAD~20
>
> show differences with recursion into the var/ submodule just fine.
That's pretty cool! Even though diff options like --stat and --name-only
still won't take into account what happened inside the submodule this
approach makes it possible to see the diff recursively. Wouldn't it make
sense add this script to contrib (after teaching it new and removed
submodules and documenting its use in a few lines after the shebang)?
next prev parent reply other threads:[~2012-09-20 19:52 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-18 3:12 git diff across submodules Kenny Simpson
2012-09-18 19:02 ` Jens Lehmann
2012-09-18 19:28 ` Junio C Hamano
2012-09-19 22:31 ` Junio C Hamano
2012-09-20 19:51 ` Jens Lehmann [this message]
2012-09-20 20:52 ` Junio C Hamano
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=505B73CE.5030009@web.de \
--to=jens.lehmann@web.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=theonetruekenny@yahoo.com \
/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).