From: Stefan Beller <sbeller@google.com>
To: jacob.keller@gmail.com
Cc: git@vger.kernel.org, daveparrish@gmail.com,
Stefan Beller <sbeller@google.com>
Subject: [PATCH 1/2] diff: submodule inline diff to initialize env array.
Date: Fri, 31 Mar 2017 16:17:32 -0700 [thread overview]
Message-ID: <20170331231733.11123-2-sbeller@google.com> (raw)
In-Reply-To: <20170331231733.11123-1-sbeller@google.com>
David reported:
> When I try to run `git diff --submodule=diff` in a submodule which has
> it's own submodules that have changes I get the error: fatal: bad
> object.
This happens, because we do not properly initialize the environment
in which the diff is run in the submodule. That means we inherit the
environment from the main process, which sets environment variables.
(Apparently we do set environment variables which we do not set
when not in a submodules, i.e. the .git directory is linked)
This commit, just like fd47ae6a5b (diff: teach diff to display
submodule difference with an inline diff, 2016-08-31) introduces bad
test code (i.e. hard coded hash values), which will be cleanup up in
a later patch.
Reported-by: David Parrish <daveparrish@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
submodule.c | 1 +
t/t4060-diff-submodule-option-diff-format.sh | 29 ++++++++++++++++++++++++++++
2 files changed, 30 insertions(+)
diff --git a/submodule.c b/submodule.c
index c52d6634c5..d84109908f 100644
--- a/submodule.c
+++ b/submodule.c
@@ -576,6 +576,7 @@ void show_submodule_inline_diff(FILE *f, const char *path,
if (!(dirty_submodule & DIRTY_SUBMODULE_MODIFIED))
argv_array_push(&cp.args, oid_to_hex(new));
+ prepare_submodule_repo_env(&cp.env_array);
if (run_command(&cp))
fprintf(f, "(diff failed)\n");
diff --git a/t/t4060-diff-submodule-option-diff-format.sh b/t/t4060-diff-submodule-option-diff-format.sh
index 7e23b55ea4..d4a3ffa69c 100755
--- a/t/t4060-diff-submodule-option-diff-format.sh
+++ b/t/t4060-diff-submodule-option-diff-format.sh
@@ -746,4 +746,33 @@ test_expect_success 'diff --submodule=diff with .git file' '
test_cmp expected actual
'
+test_expect_success 'setup nested submodule' '
+ git submodule add -f ./sm2 &&
+ git commit -a -m "add sm2" &&
+ git -C sm2 submodule add ../sm2 nested &&
+ git -C sm2 commit -a -m "nested sub"
+'
+
+test_expect_success 'move nested submodule HEAD' '
+ echo "nested content" >sm2/nested/file &&
+ git -C sm2/nested add file &&
+ git -C sm2/nested commit --allow-empty -m "new HEAD"
+'
+
+test_expect_success 'diff --submodule=diff with moved nested submodule HEAD' '
+ cat >expected <<-EOF &&
+ Submodule nested a5a65c9..b55928c:
+ diff --git a/nested/file b/nested/file
+ new file mode 100644
+ index 0000000..ca281f5
+ --- /dev/null
+ +++ b/nested/file
+ @@ -0,0 +1 @@
+ +nested content
+ EOF
+ git -C sm2 diff --submodule=diff >actual 2>err &&
+ test_must_be_empty err &&
+ test_cmp expected actual
+'
+
test_done
--
2.12.2.576.g7be6e4ba40.dirty
next prev parent reply other threads:[~2017-03-31 23:17 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-31 23:17 [PATCH 0/2] Re: git diff --submodule=diff fails with submodules in a submodule Stefan Beller
2017-03-31 23:17 ` Stefan Beller [this message]
2017-03-31 23:17 ` [PATCH 2/2] diff: recurse into nested submodules for inline diff Stefan Beller
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=20170331231733.11123-2-sbeller@google.com \
--to=sbeller@google.com \
--cc=daveparrish@gmail.com \
--cc=git@vger.kernel.org \
--cc=jacob.keller@gmail.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).