2016-08-31 23:27:25 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2009 Jens Lehmann, based on t7401 by Ping Yin
|
|
|
|
# Copyright (c) 2011 Alexey Shumkin (+ non-UTF-8 commit encoding tests)
|
|
|
|
# Copyright (c) 2016 Jacob Keller (copy + convert to --submodule=diff)
|
|
|
|
#
|
|
|
|
|
|
|
|
test_description='Support for diff format verbose submodule difference in git diff
|
|
|
|
|
|
|
|
This test tries to verify the sanity of --submodule=diff option of git diff.
|
|
|
|
'
|
|
|
|
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
# Tested non-UTF-8 encoding
|
|
|
|
test_encoding="ISO8859-1"
|
|
|
|
|
|
|
|
# String "added" in German (translated with Google Translate), encoded in UTF-8,
|
|
|
|
# used in sample commit log messages in add_file() function below.
|
|
|
|
added=$(printf "hinzugef\303\274gt")
|
|
|
|
|
|
|
|
add_file () {
|
|
|
|
(
|
|
|
|
cd "$1" &&
|
|
|
|
shift &&
|
|
|
|
for name
|
|
|
|
do
|
|
|
|
echo "$name" >"$name" &&
|
|
|
|
git add "$name" &&
|
|
|
|
test_tick &&
|
|
|
|
# "git commit -m" would break MinGW, as Windows refuse to pass
|
|
|
|
# $test_encoding encoded parameter to git.
|
|
|
|
echo "Add $name ($added $name)" | iconv -f utf-8 -t $test_encoding |
|
|
|
|
git -c "i18n.commitEncoding=$test_encoding" commit -F -
|
|
|
|
done >/dev/null &&
|
|
|
|
git rev-parse --short --verify HEAD
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
commit_file () {
|
|
|
|
test_tick &&
|
|
|
|
git commit "$@" -m "Commit $*" >/dev/null
|
|
|
|
}
|
|
|
|
|
2020-02-07 00:52:43 +00:00
|
|
|
diff_cmp () {
|
|
|
|
for i in "$1" "$2"
|
|
|
|
do
|
|
|
|
sed -e 's/^index 0000000\.\.[0-9a-f]*/index 0000000..1234567/' \
|
|
|
|
-e 's/^index [0-9a-f]*\.\.[0-9a-f]*/index 1234567..89abcde/' \
|
|
|
|
"$i" >"$i.compare" || return 1
|
|
|
|
done &&
|
|
|
|
test_cmp "$1.compare" "$2.compare" &&
|
|
|
|
rm -f "$1.compare" "$2.compare"
|
|
|
|
}
|
|
|
|
|
2016-08-31 23:27:25 +00:00
|
|
|
test_expect_success 'setup repository' '
|
|
|
|
test_create_repo sm1 &&
|
|
|
|
add_file . foo &&
|
|
|
|
head1=$(add_file sm1 foo1 foo2) &&
|
|
|
|
fullhead1=$(git -C sm1 rev-parse --verify HEAD)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'added submodule' '
|
|
|
|
git add sm1 &&
|
|
|
|
git diff-index -p --submodule=diff HEAD >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
|
|
|
Submodule sm1 0000000...$head1 (new submodule)
|
|
|
|
diff --git a/sm1/foo1 b/sm1/foo1
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000..1715acd
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/sm1/foo1
|
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+foo1
|
|
|
|
diff --git a/sm1/foo2 b/sm1/foo2
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000..54b060e
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/sm1/foo2
|
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+foo2
|
|
|
|
EOF
|
2020-02-07 00:52:43 +00:00
|
|
|
diff_cmp expected actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'added submodule, set diff.submodule' '
|
|
|
|
test_config diff.submodule log &&
|
|
|
|
git add sm1 &&
|
|
|
|
git diff-index -p --submodule=diff HEAD >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
|
|
|
Submodule sm1 0000000...$head1 (new submodule)
|
|
|
|
diff --git a/sm1/foo1 b/sm1/foo1
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000..1715acd
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/sm1/foo1
|
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+foo1
|
|
|
|
diff --git a/sm1/foo2 b/sm1/foo2
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000..54b060e
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/sm1/foo2
|
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+foo2
|
|
|
|
EOF
|
2020-02-07 00:52:43 +00:00
|
|
|
diff_cmp expected actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '--submodule=short overrides diff.submodule' '
|
|
|
|
test_config diff.submodule log &&
|
|
|
|
git add sm1 &&
|
|
|
|
git diff --submodule=short --cached >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
|
|
|
diff --git a/sm1 b/sm1
|
|
|
|
new file mode 160000
|
|
|
|
index 0000000..$head1
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/sm1
|
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+Subproject commit $fullhead1
|
|
|
|
EOF
|
2020-02-07 00:52:43 +00:00
|
|
|
diff_cmp expected actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'diff.submodule does not affect plumbing' '
|
|
|
|
test_config diff.submodule log &&
|
|
|
|
git diff-index -p HEAD >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
|
|
|
diff --git a/sm1 b/sm1
|
|
|
|
new file mode 160000
|
|
|
|
index 0000000..$head1
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/sm1
|
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+Subproject commit $fullhead1
|
|
|
|
EOF
|
2020-02-07 00:52:43 +00:00
|
|
|
diff_cmp expected actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
commit_file sm1 &&
|
|
|
|
head2=$(add_file sm1 foo3)
|
|
|
|
|
|
|
|
test_expect_success 'modified submodule(forward)' '
|
|
|
|
git diff-index -p --submodule=diff HEAD >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
|
|
|
Submodule sm1 $head1..$head2:
|
|
|
|
diff --git a/sm1/foo3 b/sm1/foo3
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000..c1ec6c6
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/sm1/foo3
|
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+foo3
|
|
|
|
EOF
|
2020-02-07 00:52:43 +00:00
|
|
|
diff_cmp expected actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'modified submodule(forward)' '
|
|
|
|
git diff --submodule=diff >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
|
|
|
Submodule sm1 $head1..$head2:
|
|
|
|
diff --git a/sm1/foo3 b/sm1/foo3
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000..c1ec6c6
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/sm1/foo3
|
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+foo3
|
|
|
|
EOF
|
2020-02-07 00:52:43 +00:00
|
|
|
diff_cmp expected actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'modified submodule(forward) --submodule' '
|
|
|
|
git diff --submodule >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
|
|
|
Submodule sm1 $head1..$head2:
|
|
|
|
> Add foo3 ($added foo3)
|
|
|
|
EOF
|
2020-02-07 00:52:43 +00:00
|
|
|
diff_cmp expected actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
fullhead2=$(cd sm1; git rev-parse --verify HEAD)
|
|
|
|
test_expect_success 'modified submodule(forward) --submodule=short' '
|
|
|
|
git diff --submodule=short >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
|
|
|
diff --git a/sm1 b/sm1
|
|
|
|
index $head1..$head2 160000
|
|
|
|
--- a/sm1
|
|
|
|
+++ b/sm1
|
|
|
|
@@ -1 +1 @@
|
|
|
|
-Subproject commit $fullhead1
|
|
|
|
+Subproject commit $fullhead2
|
|
|
|
EOF
|
2020-02-07 00:52:43 +00:00
|
|
|
diff_cmp expected actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
commit_file sm1 &&
|
|
|
|
head3=$(
|
|
|
|
cd sm1 &&
|
|
|
|
git reset --hard HEAD~2 >/dev/null &&
|
|
|
|
git rev-parse --short --verify HEAD
|
|
|
|
)
|
|
|
|
|
|
|
|
test_expect_success 'modified submodule(backward)' '
|
|
|
|
git diff-index -p --submodule=diff HEAD >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
|
|
|
Submodule sm1 $head2..$head3 (rewind):
|
|
|
|
diff --git a/sm1/foo2 b/sm1/foo2
|
|
|
|
deleted file mode 100644
|
|
|
|
index 54b060e..0000000
|
|
|
|
--- a/sm1/foo2
|
|
|
|
+++ /dev/null
|
|
|
|
@@ -1 +0,0 @@
|
|
|
|
-foo2
|
|
|
|
diff --git a/sm1/foo3 b/sm1/foo3
|
|
|
|
deleted file mode 100644
|
|
|
|
index c1ec6c6..0000000
|
|
|
|
--- a/sm1/foo3
|
|
|
|
+++ /dev/null
|
|
|
|
@@ -1 +0,0 @@
|
|
|
|
-foo3
|
|
|
|
EOF
|
2020-02-07 00:52:43 +00:00
|
|
|
diff_cmp expected actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
head4=$(add_file sm1 foo4 foo5)
|
|
|
|
test_expect_success 'modified submodule(backward and forward)' '
|
|
|
|
git diff-index -p --submodule=diff HEAD >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
|
|
|
Submodule sm1 $head2...$head4:
|
|
|
|
diff --git a/sm1/foo2 b/sm1/foo2
|
|
|
|
deleted file mode 100644
|
|
|
|
index 54b060e..0000000
|
|
|
|
--- a/sm1/foo2
|
|
|
|
+++ /dev/null
|
|
|
|
@@ -1 +0,0 @@
|
|
|
|
-foo2
|
|
|
|
diff --git a/sm1/foo3 b/sm1/foo3
|
|
|
|
deleted file mode 100644
|
|
|
|
index c1ec6c6..0000000
|
|
|
|
--- a/sm1/foo3
|
|
|
|
+++ /dev/null
|
|
|
|
@@ -1 +0,0 @@
|
|
|
|
-foo3
|
|
|
|
diff --git a/sm1/foo4 b/sm1/foo4
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000..a0016db
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/sm1/foo4
|
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+foo4
|
|
|
|
diff --git a/sm1/foo5 b/sm1/foo5
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000..d6f2413
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/sm1/foo5
|
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+foo5
|
|
|
|
EOF
|
2020-02-07 00:52:43 +00:00
|
|
|
diff_cmp expected actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
commit_file sm1 &&
|
|
|
|
mv sm1 sm1-bak &&
|
|
|
|
echo sm1 >sm1 &&
|
|
|
|
head5=$(git hash-object sm1 | cut -c1-7) &&
|
|
|
|
git add sm1 &&
|
|
|
|
rm -f sm1 &&
|
|
|
|
mv sm1-bak sm1
|
|
|
|
|
|
|
|
test_expect_success 'typechanged submodule(submodule->blob), --cached' '
|
|
|
|
git diff --submodule=diff --cached >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
|
|
|
Submodule sm1 $head4...0000000 (submodule deleted)
|
|
|
|
diff --git a/sm1/foo1 b/sm1/foo1
|
|
|
|
deleted file mode 100644
|
|
|
|
index 1715acd..0000000
|
|
|
|
--- a/sm1/foo1
|
|
|
|
+++ /dev/null
|
|
|
|
@@ -1 +0,0 @@
|
|
|
|
-foo1
|
|
|
|
diff --git a/sm1/foo4 b/sm1/foo4
|
|
|
|
deleted file mode 100644
|
|
|
|
index a0016db..0000000
|
|
|
|
--- a/sm1/foo4
|
|
|
|
+++ /dev/null
|
|
|
|
@@ -1 +0,0 @@
|
|
|
|
-foo4
|
|
|
|
diff --git a/sm1/foo5 b/sm1/foo5
|
|
|
|
deleted file mode 100644
|
|
|
|
index d6f2413..0000000
|
|
|
|
--- a/sm1/foo5
|
|
|
|
+++ /dev/null
|
|
|
|
@@ -1 +0,0 @@
|
|
|
|
-foo5
|
|
|
|
diff --git a/sm1 b/sm1
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000..9da5fb8
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/sm1
|
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+sm1
|
|
|
|
EOF
|
2020-02-07 00:52:43 +00:00
|
|
|
diff_cmp expected actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'typechanged submodule(submodule->blob)' '
|
|
|
|
git diff --submodule=diff >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
|
|
|
diff --git a/sm1 b/sm1
|
|
|
|
deleted file mode 100644
|
|
|
|
index 9da5fb8..0000000
|
|
|
|
--- a/sm1
|
|
|
|
+++ /dev/null
|
|
|
|
@@ -1 +0,0 @@
|
|
|
|
-sm1
|
|
|
|
Submodule sm1 0000000...$head4 (new submodule)
|
|
|
|
diff --git a/sm1/foo1 b/sm1/foo1
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000..1715acd
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/sm1/foo1
|
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+foo1
|
|
|
|
diff --git a/sm1/foo4 b/sm1/foo4
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000..a0016db
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/sm1/foo4
|
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+foo4
|
|
|
|
diff --git a/sm1/foo5 b/sm1/foo5
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000..d6f2413
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/sm1/foo5
|
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+foo5
|
|
|
|
EOF
|
2020-02-07 00:52:43 +00:00
|
|
|
diff_cmp expected actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
rm -rf sm1 &&
|
|
|
|
git checkout-index sm1
|
|
|
|
test_expect_success 'typechanged submodule(submodule->blob)' '
|
|
|
|
git diff-index -p --submodule=diff HEAD >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
|
|
|
Submodule sm1 $head4...0000000 (submodule deleted)
|
|
|
|
diff --git a/sm1 b/sm1
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000..9da5fb8
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/sm1
|
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+sm1
|
|
|
|
EOF
|
2020-02-07 00:52:43 +00:00
|
|
|
diff_cmp expected actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
rm -f sm1 &&
|
|
|
|
test_create_repo sm1 &&
|
|
|
|
head6=$(add_file sm1 foo6 foo7)
|
|
|
|
test_expect_success 'nonexistent commit' '
|
|
|
|
git diff-index -p --submodule=diff HEAD >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
|
|
|
Submodule sm1 $head4...$head6 (commits not present)
|
|
|
|
EOF
|
2020-02-07 00:52:43 +00:00
|
|
|
diff_cmp expected actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
commit_file
|
|
|
|
test_expect_success 'typechanged submodule(blob->submodule)' '
|
|
|
|
git diff-index -p --submodule=diff HEAD >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
|
|
|
diff --git a/sm1 b/sm1
|
|
|
|
deleted file mode 100644
|
|
|
|
index 9da5fb8..0000000
|
|
|
|
--- a/sm1
|
|
|
|
+++ /dev/null
|
|
|
|
@@ -1 +0,0 @@
|
|
|
|
-sm1
|
|
|
|
Submodule sm1 0000000...$head6 (new submodule)
|
|
|
|
diff --git a/sm1/foo6 b/sm1/foo6
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000..462398b
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/sm1/foo6
|
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+foo6
|
|
|
|
diff --git a/sm1/foo7 b/sm1/foo7
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000..6e9262c
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/sm1/foo7
|
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+foo7
|
|
|
|
EOF
|
2020-02-07 00:52:43 +00:00
|
|
|
diff_cmp expected actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
commit_file sm1 &&
|
|
|
|
test_expect_success 'submodule is up to date' '
|
2020-02-07 00:52:43 +00:00
|
|
|
head7=$(git -C sm1 rev-parse --short --verify HEAD) &&
|
2016-08-31 23:27:25 +00:00
|
|
|
git diff-index -p --submodule=diff HEAD >actual &&
|
tests: use 'test_must_be_empty' instead of 'test_cmp <empty> <out>'
Using 'test_must_be_empty' is shorter and more idiomatic than
>empty &&
test_cmp empty out
as it saves the creation of an empty file. Furthermore, sometimes the
expected empty file doesn't have such a descriptive name like 'empty',
and its creation is far away from the place where it's finally used
for comparison (e.g. in 't7600-merge.sh', where two expected empty
files are created in the 'setup' test, but are used only about 500
lines later).
These cases were found by instrumenting 'test_cmp' to error out the
test script when it's used to compare empty files, and then converted
manually.
Note that even after this patch there still remain a lot of cases
where we use 'test_cmp' to check empty files:
- Sometimes the expected output is not hard-coded in the test, but
'test_cmp' is used to ensure that two similar git commands produce
the same output, and that output happens to be empty, e.g. the
test 'submodule update --merge - ignores --merge for new
submodules' in 't7406-submodule-update.sh'.
- Repetitive common tasks, including preparing the expected results
and running 'test_cmp', are often extracted into a helper
function, and some of this helper's callsites expect no output.
- For the same reason as above, the whole 'test_expect_success'
block is within a helper function, e.g. in 't3070-wildmatch.sh'.
- Or 'test_cmp' is invoked in a loop, e.g. the test 'cvs update
(-p)' in 't9400-git-cvsserver-server.sh'.
Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-19 21:57:25 +00:00
|
|
|
test_must_be_empty actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'submodule contains untracked content' '
|
|
|
|
echo new > sm1/new-file &&
|
2020-11-10 08:39:00 +00:00
|
|
|
git diff-index -p --ignore-submodules=none --submodule=diff HEAD >actual &&
|
2016-08-31 23:27:25 +00:00
|
|
|
cat >expected <<-EOF &&
|
|
|
|
Submodule sm1 contains untracked content
|
|
|
|
EOF
|
2020-02-07 00:52:43 +00:00
|
|
|
diff_cmp expected actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'submodule contains untracked content (untracked ignored)' '
|
2020-11-10 08:39:00 +00:00
|
|
|
git diff-index -p --submodule=diff HEAD >actual &&
|
2018-08-19 21:57:22 +00:00
|
|
|
test_must_be_empty actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'submodule contains untracked content (dirty ignored)' '
|
|
|
|
git diff-index -p --ignore-submodules=dirty --submodule=diff HEAD >actual &&
|
2018-08-19 21:57:22 +00:00
|
|
|
test_must_be_empty actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'submodule contains untracked content (all ignored)' '
|
|
|
|
git diff-index -p --ignore-submodules=all --submodule=diff HEAD >actual &&
|
2018-08-19 21:57:22 +00:00
|
|
|
test_must_be_empty actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'submodule contains untracked and modified content' '
|
|
|
|
echo new > sm1/foo6 &&
|
2020-11-10 08:39:00 +00:00
|
|
|
git diff-index -p --ignore-submodules=none --submodule=diff HEAD >actual &&
|
2016-08-31 23:27:25 +00:00
|
|
|
cat >expected <<-EOF &&
|
|
|
|
Submodule sm1 contains untracked content
|
|
|
|
Submodule sm1 contains modified content
|
|
|
|
diff --git a/sm1/foo6 b/sm1/foo6
|
|
|
|
index 462398b..3e75765 100644
|
|
|
|
--- a/sm1/foo6
|
|
|
|
+++ b/sm1/foo6
|
|
|
|
@@ -1 +1 @@
|
|
|
|
-foo6
|
|
|
|
+new
|
|
|
|
EOF
|
2020-02-07 00:52:43 +00:00
|
|
|
diff_cmp expected actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
# NOT OK
|
|
|
|
test_expect_success 'submodule contains untracked and modified content (untracked ignored)' '
|
|
|
|
echo new > sm1/foo6 &&
|
2020-11-10 08:39:00 +00:00
|
|
|
git diff-index -p --submodule=diff HEAD >actual &&
|
2016-08-31 23:27:25 +00:00
|
|
|
cat >expected <<-EOF &&
|
|
|
|
Submodule sm1 contains modified content
|
|
|
|
diff --git a/sm1/foo6 b/sm1/foo6
|
|
|
|
index 462398b..3e75765 100644
|
|
|
|
--- a/sm1/foo6
|
|
|
|
+++ b/sm1/foo6
|
|
|
|
@@ -1 +1 @@
|
|
|
|
-foo6
|
|
|
|
+new
|
|
|
|
EOF
|
2020-02-07 00:52:43 +00:00
|
|
|
diff_cmp expected actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'submodule contains untracked and modified content (dirty ignored)' '
|
|
|
|
echo new > sm1/foo6 &&
|
|
|
|
git diff-index -p --ignore-submodules=dirty --submodule=diff HEAD >actual &&
|
2018-08-19 21:57:22 +00:00
|
|
|
test_must_be_empty actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'submodule contains untracked and modified content (all ignored)' '
|
|
|
|
echo new > sm1/foo6 &&
|
|
|
|
git diff-index -p --ignore-submodules --submodule=diff HEAD >actual &&
|
2018-08-19 21:57:22 +00:00
|
|
|
test_must_be_empty actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'submodule contains modified content' '
|
|
|
|
rm -f sm1/new-file &&
|
|
|
|
git diff-index -p --submodule=diff HEAD >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
|
|
|
Submodule sm1 contains modified content
|
|
|
|
diff --git a/sm1/foo6 b/sm1/foo6
|
|
|
|
index 462398b..3e75765 100644
|
|
|
|
--- a/sm1/foo6
|
|
|
|
+++ b/sm1/foo6
|
|
|
|
@@ -1 +1 @@
|
|
|
|
-foo6
|
|
|
|
+new
|
|
|
|
EOF
|
2020-02-07 00:52:43 +00:00
|
|
|
diff_cmp expected actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
(cd sm1; git commit -mchange foo6 >/dev/null) &&
|
|
|
|
head8=$(cd sm1; git rev-parse --short --verify HEAD) &&
|
|
|
|
test_expect_success 'submodule is modified' '
|
|
|
|
git diff-index -p --submodule=diff HEAD >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
2020-02-07 00:52:43 +00:00
|
|
|
Submodule sm1 $head7..$head8:
|
2016-08-31 23:27:25 +00:00
|
|
|
diff --git a/sm1/foo6 b/sm1/foo6
|
|
|
|
index 462398b..3e75765 100644
|
|
|
|
--- a/sm1/foo6
|
|
|
|
+++ b/sm1/foo6
|
|
|
|
@@ -1 +1 @@
|
|
|
|
-foo6
|
|
|
|
+new
|
|
|
|
EOF
|
2020-02-07 00:52:43 +00:00
|
|
|
diff_cmp expected actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'modified submodule contains untracked content' '
|
|
|
|
echo new > sm1/new-file &&
|
2020-11-10 08:39:00 +00:00
|
|
|
git diff-index -p --ignore-submodules=none --submodule=diff HEAD >actual &&
|
2016-08-31 23:27:25 +00:00
|
|
|
cat >expected <<-EOF &&
|
|
|
|
Submodule sm1 contains untracked content
|
2020-02-07 00:52:43 +00:00
|
|
|
Submodule sm1 $head7..$head8:
|
2016-08-31 23:27:25 +00:00
|
|
|
diff --git a/sm1/foo6 b/sm1/foo6
|
|
|
|
index 462398b..3e75765 100644
|
|
|
|
--- a/sm1/foo6
|
|
|
|
+++ b/sm1/foo6
|
|
|
|
@@ -1 +1 @@
|
|
|
|
-foo6
|
|
|
|
+new
|
|
|
|
EOF
|
2020-02-07 00:52:43 +00:00
|
|
|
diff_cmp expected actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'modified submodule contains untracked content (untracked ignored)' '
|
2020-11-10 08:39:00 +00:00
|
|
|
git diff-index -p --submodule=diff HEAD >actual &&
|
2016-08-31 23:27:25 +00:00
|
|
|
cat >expected <<-EOF &&
|
2020-02-07 00:52:43 +00:00
|
|
|
Submodule sm1 $head7..$head8:
|
2016-08-31 23:27:25 +00:00
|
|
|
diff --git a/sm1/foo6 b/sm1/foo6
|
|
|
|
index 462398b..3e75765 100644
|
|
|
|
--- a/sm1/foo6
|
|
|
|
+++ b/sm1/foo6
|
|
|
|
@@ -1 +1 @@
|
|
|
|
-foo6
|
|
|
|
+new
|
|
|
|
EOF
|
2020-02-07 00:52:43 +00:00
|
|
|
diff_cmp expected actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'modified submodule contains untracked content (dirty ignored)' '
|
|
|
|
git diff-index -p --ignore-submodules=dirty --submodule=diff HEAD >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
2020-02-07 00:52:43 +00:00
|
|
|
Submodule sm1 $head7..$head8:
|
2016-08-31 23:27:25 +00:00
|
|
|
diff --git a/sm1/foo6 b/sm1/foo6
|
|
|
|
index 462398b..3e75765 100644
|
|
|
|
--- a/sm1/foo6
|
|
|
|
+++ b/sm1/foo6
|
|
|
|
@@ -1 +1 @@
|
|
|
|
-foo6
|
|
|
|
+new
|
|
|
|
EOF
|
2020-02-07 00:52:43 +00:00
|
|
|
diff_cmp expected actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'modified submodule contains untracked content (all ignored)' '
|
|
|
|
git diff-index -p --ignore-submodules=all --submodule=diff HEAD >actual &&
|
2018-08-19 21:57:22 +00:00
|
|
|
test_must_be_empty actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'modified submodule contains untracked and modified content' '
|
|
|
|
echo modification >> sm1/foo6 &&
|
2020-11-10 08:39:00 +00:00
|
|
|
git diff-index -p --ignore-submodules=none --submodule=diff HEAD >actual &&
|
2016-08-31 23:27:25 +00:00
|
|
|
cat >expected <<-EOF &&
|
|
|
|
Submodule sm1 contains untracked content
|
|
|
|
Submodule sm1 contains modified content
|
2020-02-07 00:52:43 +00:00
|
|
|
Submodule sm1 $head7..$head8:
|
2016-08-31 23:27:25 +00:00
|
|
|
diff --git a/sm1/foo6 b/sm1/foo6
|
|
|
|
index 462398b..dfda541 100644
|
|
|
|
--- a/sm1/foo6
|
|
|
|
+++ b/sm1/foo6
|
|
|
|
@@ -1 +1,2 @@
|
|
|
|
-foo6
|
|
|
|
+new
|
|
|
|
+modification
|
|
|
|
EOF
|
2020-02-07 00:52:43 +00:00
|
|
|
diff_cmp expected actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'modified submodule contains untracked and modified content (untracked ignored)' '
|
|
|
|
echo modification >> sm1/foo6 &&
|
2020-11-10 08:39:00 +00:00
|
|
|
git diff-index -p --submodule=diff HEAD >actual &&
|
2016-08-31 23:27:25 +00:00
|
|
|
cat >expected <<-EOF &&
|
|
|
|
Submodule sm1 contains modified content
|
2020-02-07 00:52:43 +00:00
|
|
|
Submodule sm1 $head7..$head8:
|
2016-08-31 23:27:25 +00:00
|
|
|
diff --git a/sm1/foo6 b/sm1/foo6
|
|
|
|
index 462398b..e20e2d9 100644
|
|
|
|
--- a/sm1/foo6
|
|
|
|
+++ b/sm1/foo6
|
|
|
|
@@ -1 +1,3 @@
|
|
|
|
-foo6
|
|
|
|
+new
|
|
|
|
+modification
|
|
|
|
+modification
|
|
|
|
EOF
|
2020-02-07 00:52:43 +00:00
|
|
|
diff_cmp expected actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'modified submodule contains untracked and modified content (dirty ignored)' '
|
|
|
|
echo modification >> sm1/foo6 &&
|
|
|
|
git diff-index -p --ignore-submodules=dirty --submodule=diff HEAD >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
2020-02-07 00:52:43 +00:00
|
|
|
Submodule sm1 $head7..$head8:
|
2016-08-31 23:27:25 +00:00
|
|
|
diff --git a/sm1/foo6 b/sm1/foo6
|
|
|
|
index 462398b..3e75765 100644
|
|
|
|
--- a/sm1/foo6
|
|
|
|
+++ b/sm1/foo6
|
|
|
|
@@ -1 +1 @@
|
|
|
|
-foo6
|
|
|
|
+new
|
|
|
|
EOF
|
2020-02-07 00:52:43 +00:00
|
|
|
diff_cmp expected actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'modified submodule contains untracked and modified content (all ignored)' '
|
|
|
|
echo modification >> sm1/foo6 &&
|
|
|
|
git diff-index -p --ignore-submodules --submodule=diff HEAD >actual &&
|
2018-08-19 21:57:22 +00:00
|
|
|
test_must_be_empty actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
# NOT OK
|
|
|
|
test_expect_success 'modified submodule contains modified content' '
|
|
|
|
rm -f sm1/new-file &&
|
|
|
|
git diff-index -p --submodule=diff HEAD >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
|
|
|
Submodule sm1 contains modified content
|
2020-02-07 00:52:43 +00:00
|
|
|
Submodule sm1 $head7..$head8:
|
2016-08-31 23:27:25 +00:00
|
|
|
diff --git a/sm1/foo6 b/sm1/foo6
|
|
|
|
index 462398b..ac466ca 100644
|
|
|
|
--- a/sm1/foo6
|
|
|
|
+++ b/sm1/foo6
|
|
|
|
@@ -1 +1,5 @@
|
|
|
|
-foo6
|
|
|
|
+new
|
|
|
|
+modification
|
|
|
|
+modification
|
|
|
|
+modification
|
|
|
|
+modification
|
|
|
|
EOF
|
2020-02-07 00:52:43 +00:00
|
|
|
diff_cmp expected actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
rm -rf sm1
|
|
|
|
test_expect_success 'deleted submodule' '
|
|
|
|
git diff-index -p --submodule=diff HEAD >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
2020-02-07 00:52:43 +00:00
|
|
|
Submodule sm1 $head7...0000000 (submodule deleted)
|
2016-08-31 23:27:25 +00:00
|
|
|
EOF
|
2020-02-07 00:52:43 +00:00
|
|
|
diff_cmp expected actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
2017-06-14 10:58:25 +00:00
|
|
|
test_expect_success 'create second submodule' '
|
|
|
|
test_create_repo sm2 &&
|
2020-02-07 00:52:43 +00:00
|
|
|
head9=$(add_file sm2 foo8 foo9) &&
|
2017-06-14 10:58:25 +00:00
|
|
|
git add sm2
|
|
|
|
'
|
2016-08-31 23:27:25 +00:00
|
|
|
|
|
|
|
test_expect_success 'multiple submodules' '
|
|
|
|
git diff-index -p --submodule=diff HEAD >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
2020-02-07 00:52:43 +00:00
|
|
|
Submodule sm1 $head7...0000000 (submodule deleted)
|
|
|
|
Submodule sm2 0000000...$head9 (new submodule)
|
2016-08-31 23:27:25 +00:00
|
|
|
diff --git a/sm2/foo8 b/sm2/foo8
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000..db9916b
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/sm2/foo8
|
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+foo8
|
|
|
|
diff --git a/sm2/foo9 b/sm2/foo9
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000..9c3b4f6
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/sm2/foo9
|
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+foo9
|
|
|
|
EOF
|
2020-02-07 00:52:43 +00:00
|
|
|
diff_cmp expected actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'path filter' '
|
|
|
|
git diff-index -p --submodule=diff HEAD sm2 >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
2020-02-07 00:52:43 +00:00
|
|
|
Submodule sm2 0000000...$head9 (new submodule)
|
2016-08-31 23:27:25 +00:00
|
|
|
diff --git a/sm2/foo8 b/sm2/foo8
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000..db9916b
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/sm2/foo8
|
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+foo8
|
|
|
|
diff --git a/sm2/foo9 b/sm2/foo9
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000..9c3b4f6
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/sm2/foo9
|
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+foo9
|
|
|
|
EOF
|
2020-02-07 00:52:43 +00:00
|
|
|
diff_cmp expected actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
diff --submodule=diff: do not fail on ever-initialied deleted submodules
If you have ever initialized a submodule, open_submodule will open it.
If you then delete the submodule's worktree directory (but don't
remove it from .gitmodules), git diff --submodule=diff would error out
as it attempted to chdir into the now-deleted working tree directory.
This only matters if the submodules git dir is absorbed. If not, then
we no longer have anywhere to run the diff. But that case does not
trigger this error, because in that case, open_submodule fails, so we
don't resolve a left commit, so we exit early, which is the only thing
we could do.
If absorbed, then we can run the diff from the submodule's absorbed
git dir (.git/modules/sm2). In practice, that's a bit more
complicated, because `git diff` expects to be run from inside a
working directory, not a git dir. So it looks in the config for
core.worktree, and does chdir("../../../sm2"), which is the very dir
that we're trying to avoid visiting because it's been deleted. We
work around this by setting GIT_WORK_TREE (and GIT_DIR) to ".". It is
little weird to set GIT_WORK_TREE to something that is not a working
tree just to avoid an unnecessary chdir, but it works.
Signed-off-by: David Turner <dturner@twosigma.com
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-08-31 13:12:56 +00:00
|
|
|
cat >.gitmodules <<-EOF
|
|
|
|
[submodule "sm2"]
|
|
|
|
path = sm2
|
|
|
|
url = bogus_url
|
|
|
|
EOF
|
|
|
|
git add .gitmodules
|
|
|
|
commit_file sm2 .gitmodules
|
|
|
|
|
2016-08-31 23:27:25 +00:00
|
|
|
test_expect_success 'given commit' '
|
|
|
|
git diff-index -p --submodule=diff HEAD^ >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
diff --submodule=diff: do not fail on ever-initialied deleted submodules
If you have ever initialized a submodule, open_submodule will open it.
If you then delete the submodule's worktree directory (but don't
remove it from .gitmodules), git diff --submodule=diff would error out
as it attempted to chdir into the now-deleted working tree directory.
This only matters if the submodules git dir is absorbed. If not, then
we no longer have anywhere to run the diff. But that case does not
trigger this error, because in that case, open_submodule fails, so we
don't resolve a left commit, so we exit early, which is the only thing
we could do.
If absorbed, then we can run the diff from the submodule's absorbed
git dir (.git/modules/sm2). In practice, that's a bit more
complicated, because `git diff` expects to be run from inside a
working directory, not a git dir. So it looks in the config for
core.worktree, and does chdir("../../../sm2"), which is the very dir
that we're trying to avoid visiting because it's been deleted. We
work around this by setting GIT_WORK_TREE (and GIT_DIR) to ".". It is
little weird to set GIT_WORK_TREE to something that is not a working
tree just to avoid an unnecessary chdir, but it works.
Signed-off-by: David Turner <dturner@twosigma.com
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-08-31 13:12:56 +00:00
|
|
|
diff --git a/.gitmodules b/.gitmodules
|
|
|
|
new file mode 100644
|
|
|
|
index 1234567..89abcde
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/.gitmodules
|
|
|
|
@@ -0,0 +1,3 @@
|
|
|
|
+[submodule "sm2"]
|
|
|
|
+path = sm2
|
|
|
|
+url = bogus_url
|
2020-02-07 00:52:43 +00:00
|
|
|
Submodule sm1 $head7...0000000 (submodule deleted)
|
|
|
|
Submodule sm2 0000000...$head9 (new submodule)
|
2016-08-31 23:27:25 +00:00
|
|
|
diff --git a/sm2/foo8 b/sm2/foo8
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000..db9916b
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/sm2/foo8
|
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+foo8
|
|
|
|
diff --git a/sm2/foo9 b/sm2/foo9
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000..9c3b4f6
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/sm2/foo9
|
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+foo9
|
|
|
|
EOF
|
2020-02-07 00:52:43 +00:00
|
|
|
diff_cmp expected actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'setup .git file for sm2' '
|
diff --submodule=diff: do not fail on ever-initialied deleted submodules
If you have ever initialized a submodule, open_submodule will open it.
If you then delete the submodule's worktree directory (but don't
remove it from .gitmodules), git diff --submodule=diff would error out
as it attempted to chdir into the now-deleted working tree directory.
This only matters if the submodules git dir is absorbed. If not, then
we no longer have anywhere to run the diff. But that case does not
trigger this error, because in that case, open_submodule fails, so we
don't resolve a left commit, so we exit early, which is the only thing
we could do.
If absorbed, then we can run the diff from the submodule's absorbed
git dir (.git/modules/sm2). In practice, that's a bit more
complicated, because `git diff` expects to be run from inside a
working directory, not a git dir. So it looks in the config for
core.worktree, and does chdir("../../../sm2"), which is the very dir
that we're trying to avoid visiting because it's been deleted. We
work around this by setting GIT_WORK_TREE (and GIT_DIR) to ".". It is
little weird to set GIT_WORK_TREE to something that is not a working
tree just to avoid an unnecessary chdir, but it works.
Signed-off-by: David Turner <dturner@twosigma.com
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-08-31 13:12:56 +00:00
|
|
|
git submodule absorbgitdirs sm2
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'diff --submodule=diff with .git file' '
|
|
|
|
git diff --submodule=diff HEAD^ >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
diff --submodule=diff: do not fail on ever-initialied deleted submodules
If you have ever initialized a submodule, open_submodule will open it.
If you then delete the submodule's worktree directory (but don't
remove it from .gitmodules), git diff --submodule=diff would error out
as it attempted to chdir into the now-deleted working tree directory.
This only matters if the submodules git dir is absorbed. If not, then
we no longer have anywhere to run the diff. But that case does not
trigger this error, because in that case, open_submodule fails, so we
don't resolve a left commit, so we exit early, which is the only thing
we could do.
If absorbed, then we can run the diff from the submodule's absorbed
git dir (.git/modules/sm2). In practice, that's a bit more
complicated, because `git diff` expects to be run from inside a
working directory, not a git dir. So it looks in the config for
core.worktree, and does chdir("../../../sm2"), which is the very dir
that we're trying to avoid visiting because it's been deleted. We
work around this by setting GIT_WORK_TREE (and GIT_DIR) to ".". It is
little weird to set GIT_WORK_TREE to something that is not a working
tree just to avoid an unnecessary chdir, but it works.
Signed-off-by: David Turner <dturner@twosigma.com
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-08-31 13:12:56 +00:00
|
|
|
diff --git a/.gitmodules b/.gitmodules
|
|
|
|
new file mode 100644
|
|
|
|
index 1234567..89abcde
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/.gitmodules
|
|
|
|
@@ -0,0 +1,3 @@
|
|
|
|
+[submodule "sm2"]
|
|
|
|
+path = sm2
|
|
|
|
+url = bogus_url
|
2020-02-07 00:52:43 +00:00
|
|
|
Submodule sm1 $head7...0000000 (submodule deleted)
|
|
|
|
Submodule sm2 0000000...$head9 (new submodule)
|
2016-08-31 23:27:25 +00:00
|
|
|
diff --git a/sm2/foo8 b/sm2/foo8
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000..db9916b
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/sm2/foo8
|
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+foo8
|
|
|
|
diff --git a/sm2/foo9 b/sm2/foo9
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000..9c3b4f6
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/sm2/foo9
|
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+foo9
|
|
|
|
EOF
|
2020-02-07 00:52:43 +00:00
|
|
|
diff_cmp expected actual
|
2016-08-31 23:27:25 +00:00
|
|
|
'
|
|
|
|
|
diff --submodule=diff: do not fail on ever-initialied deleted submodules
If you have ever initialized a submodule, open_submodule will open it.
If you then delete the submodule's worktree directory (but don't
remove it from .gitmodules), git diff --submodule=diff would error out
as it attempted to chdir into the now-deleted working tree directory.
This only matters if the submodules git dir is absorbed. If not, then
we no longer have anywhere to run the diff. But that case does not
trigger this error, because in that case, open_submodule fails, so we
don't resolve a left commit, so we exit early, which is the only thing
we could do.
If absorbed, then we can run the diff from the submodule's absorbed
git dir (.git/modules/sm2). In practice, that's a bit more
complicated, because `git diff` expects to be run from inside a
working directory, not a git dir. So it looks in the config for
core.worktree, and does chdir("../../../sm2"), which is the very dir
that we're trying to avoid visiting because it's been deleted. We
work around this by setting GIT_WORK_TREE (and GIT_DIR) to ".". It is
little weird to set GIT_WORK_TREE to something that is not a working
tree just to avoid an unnecessary chdir, but it works.
Signed-off-by: David Turner <dturner@twosigma.com
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-08-31 13:12:56 +00:00
|
|
|
mv sm2 sm2-bak
|
|
|
|
|
|
|
|
test_expect_success 'deleted submodule with .git file' '
|
|
|
|
git diff-index -p --submodule=diff HEAD >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
|
|
|
Submodule sm1 $head7...0000000 (submodule deleted)
|
|
|
|
Submodule sm2 $head9...0000000 (submodule deleted)
|
|
|
|
diff --git a/sm2/foo8 b/sm2/foo8
|
|
|
|
deleted file mode 100644
|
|
|
|
index 1234567..89abcde
|
|
|
|
--- a/sm2/foo8
|
|
|
|
+++ /dev/null
|
|
|
|
@@ -1 +0,0 @@
|
|
|
|
-foo8
|
|
|
|
diff --git a/sm2/foo9 b/sm2/foo9
|
|
|
|
deleted file mode 100644
|
|
|
|
index 1234567..89abcde
|
|
|
|
--- a/sm2/foo9
|
|
|
|
+++ /dev/null
|
|
|
|
@@ -1 +0,0 @@
|
|
|
|
-foo9
|
|
|
|
EOF
|
|
|
|
diff_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
echo submodule-to-blob>sm2
|
|
|
|
|
|
|
|
test_expect_success 'typechanged(submodule->blob) submodule with .git file' '
|
|
|
|
git diff-index -p --submodule=diff HEAD >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
|
|
|
Submodule sm1 $head7...0000000 (submodule deleted)
|
|
|
|
Submodule sm2 $head9...0000000 (submodule deleted)
|
|
|
|
diff --git a/sm2/foo8 b/sm2/foo8
|
|
|
|
deleted file mode 100644
|
|
|
|
index 1234567..89abcde
|
|
|
|
--- a/sm2/foo8
|
|
|
|
+++ /dev/null
|
|
|
|
@@ -1 +0,0 @@
|
|
|
|
-foo8
|
|
|
|
diff --git a/sm2/foo9 b/sm2/foo9
|
|
|
|
deleted file mode 100644
|
|
|
|
index 1234567..89abcde
|
|
|
|
--- a/sm2/foo9
|
|
|
|
+++ /dev/null
|
|
|
|
@@ -1 +0,0 @@
|
|
|
|
-foo9
|
|
|
|
diff --git a/sm2 b/sm2
|
|
|
|
new file mode 100644
|
|
|
|
index 1234567..89abcde
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/sm2
|
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+submodule-to-blob
|
|
|
|
EOF
|
|
|
|
diff_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
rm sm2
|
|
|
|
mv sm2-bak sm2
|
|
|
|
|
2017-03-31 23:17:32 +00:00
|
|
|
test_expect_success 'setup nested submodule' '
|
|
|
|
git -C sm2 submodule add ../sm2 nested &&
|
2020-02-07 00:52:43 +00:00
|
|
|
git -C sm2 commit -a -m "nested sub" &&
|
|
|
|
head10=$(git -C sm2 rev-parse --short --verify HEAD)
|
2017-03-31 23:17:32 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'move nested submodule HEAD' '
|
|
|
|
echo "nested content" >sm2/nested/file &&
|
|
|
|
git -C sm2/nested add file &&
|
2020-02-07 00:52:43 +00:00
|
|
|
git -C sm2/nested commit --allow-empty -m "new HEAD" &&
|
|
|
|
head11=$(git -C sm2/nested rev-parse --short --verify HEAD)
|
2017-03-31 23:17:32 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'diff --submodule=diff with moved nested submodule HEAD' '
|
|
|
|
cat >expected <<-EOF &&
|
2020-02-07 00:52:43 +00:00
|
|
|
Submodule nested $head9..$head11:
|
2017-03-31 23:17:32 +00:00
|
|
|
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 &&
|
2020-02-07 00:52:43 +00:00
|
|
|
diff_cmp expected actual
|
2017-03-31 23:17:32 +00:00
|
|
|
'
|
|
|
|
|
2017-05-04 21:43:55 +00:00
|
|
|
test_expect_success 'diff --submodule=diff recurses into nested submodules' '
|
|
|
|
cat >expected <<-EOF &&
|
diff --submodule=diff: do not fail on ever-initialied deleted submodules
If you have ever initialized a submodule, open_submodule will open it.
If you then delete the submodule's worktree directory (but don't
remove it from .gitmodules), git diff --submodule=diff would error out
as it attempted to chdir into the now-deleted working tree directory.
This only matters if the submodules git dir is absorbed. If not, then
we no longer have anywhere to run the diff. But that case does not
trigger this error, because in that case, open_submodule fails, so we
don't resolve a left commit, so we exit early, which is the only thing
we could do.
If absorbed, then we can run the diff from the submodule's absorbed
git dir (.git/modules/sm2). In practice, that's a bit more
complicated, because `git diff` expects to be run from inside a
working directory, not a git dir. So it looks in the config for
core.worktree, and does chdir("../../../sm2"), which is the very dir
that we're trying to avoid visiting because it's been deleted. We
work around this by setting GIT_WORK_TREE (and GIT_DIR) to ".". It is
little weird to set GIT_WORK_TREE to something that is not a working
tree just to avoid an unnecessary chdir, but it works.
Signed-off-by: David Turner <dturner@twosigma.com
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-08-31 13:12:56 +00:00
|
|
|
Submodule sm1 $head7...0000000 (submodule deleted)
|
2017-05-04 21:43:55 +00:00
|
|
|
Submodule sm2 contains modified content
|
2020-02-07 00:52:43 +00:00
|
|
|
Submodule sm2 $head9..$head10:
|
2017-05-04 21:43:55 +00:00
|
|
|
diff --git a/sm2/.gitmodules b/sm2/.gitmodules
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000..3a816b8
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/sm2/.gitmodules
|
|
|
|
@@ -0,0 +1,3 @@
|
|
|
|
+[submodule "nested"]
|
|
|
|
+ path = nested
|
|
|
|
+ url = ../sm2
|
2020-02-07 00:52:43 +00:00
|
|
|
Submodule nested 0000000...$head11 (new submodule)
|
2017-05-04 21:43:55 +00:00
|
|
|
diff --git a/sm2/nested/file b/sm2/nested/file
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000..ca281f5
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/sm2/nested/file
|
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+nested content
|
|
|
|
diff --git a/sm2/nested/foo8 b/sm2/nested/foo8
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000..db9916b
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/sm2/nested/foo8
|
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+foo8
|
|
|
|
diff --git a/sm2/nested/foo9 b/sm2/nested/foo9
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000..9c3b4f6
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/sm2/nested/foo9
|
|
|
|
@@ -0,0 +1 @@
|
|
|
|
+foo9
|
|
|
|
EOF
|
|
|
|
git diff --submodule=diff >actual 2>err &&
|
|
|
|
test_must_be_empty err &&
|
2020-02-07 00:52:43 +00:00
|
|
|
diff_cmp expected actual
|
2017-05-04 21:43:55 +00:00
|
|
|
'
|
|
|
|
|
diff --submodule=diff: do not fail on ever-initialied deleted submodules
If you have ever initialized a submodule, open_submodule will open it.
If you then delete the submodule's worktree directory (but don't
remove it from .gitmodules), git diff --submodule=diff would error out
as it attempted to chdir into the now-deleted working tree directory.
This only matters if the submodules git dir is absorbed. If not, then
we no longer have anywhere to run the diff. But that case does not
trigger this error, because in that case, open_submodule fails, so we
don't resolve a left commit, so we exit early, which is the only thing
we could do.
If absorbed, then we can run the diff from the submodule's absorbed
git dir (.git/modules/sm2). In practice, that's a bit more
complicated, because `git diff` expects to be run from inside a
working directory, not a git dir. So it looks in the config for
core.worktree, and does chdir("../../../sm2"), which is the very dir
that we're trying to avoid visiting because it's been deleted. We
work around this by setting GIT_WORK_TREE (and GIT_DIR) to ".". It is
little weird to set GIT_WORK_TREE to something that is not a working
tree just to avoid an unnecessary chdir, but it works.
Signed-off-by: David Turner <dturner@twosigma.com
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-08-31 13:12:56 +00:00
|
|
|
(cd sm2; commit_file nested)
|
|
|
|
commit_file sm2
|
|
|
|
head12=$(cd sm2; git rev-parse --short --verify HEAD)
|
|
|
|
|
|
|
|
mv sm2 sm2-bak
|
|
|
|
|
|
|
|
test_expect_success 'diff --submodule=diff recurses into deleted nested submodules' '
|
|
|
|
cat >expected <<-EOF &&
|
|
|
|
Submodule sm1 $head7...0000000 (submodule deleted)
|
|
|
|
Submodule sm2 $head12...0000000 (submodule deleted)
|
|
|
|
diff --git a/sm2/.gitmodules b/sm2/.gitmodules
|
|
|
|
deleted file mode 100644
|
|
|
|
index 3a816b8..0000000
|
|
|
|
--- a/sm2/.gitmodules
|
|
|
|
+++ /dev/null
|
|
|
|
@@ -1,3 +0,0 @@
|
|
|
|
-[submodule "nested"]
|
|
|
|
- path = nested
|
|
|
|
- url = ../sm2
|
|
|
|
diff --git a/sm2/foo8 b/sm2/foo8
|
|
|
|
deleted file mode 100644
|
|
|
|
index db9916b..0000000
|
|
|
|
--- a/sm2/foo8
|
|
|
|
+++ /dev/null
|
|
|
|
@@ -1 +0,0 @@
|
|
|
|
-foo8
|
|
|
|
diff --git a/sm2/foo9 b/sm2/foo9
|
|
|
|
deleted file mode 100644
|
|
|
|
index 9c3b4f6..0000000
|
|
|
|
--- a/sm2/foo9
|
|
|
|
+++ /dev/null
|
|
|
|
@@ -1 +0,0 @@
|
|
|
|
-foo9
|
|
|
|
Submodule nested $head11...0000000 (submodule deleted)
|
|
|
|
diff --git a/sm2/nested/file b/sm2/nested/file
|
|
|
|
deleted file mode 100644
|
|
|
|
index ca281f5..0000000
|
|
|
|
--- a/sm2/nested/file
|
|
|
|
+++ /dev/null
|
|
|
|
@@ -1 +0,0 @@
|
|
|
|
-nested content
|
|
|
|
diff --git a/sm2/nested/foo8 b/sm2/nested/foo8
|
|
|
|
deleted file mode 100644
|
|
|
|
index db9916b..0000000
|
|
|
|
--- a/sm2/nested/foo8
|
|
|
|
+++ /dev/null
|
|
|
|
@@ -1 +0,0 @@
|
|
|
|
-foo8
|
|
|
|
diff --git a/sm2/nested/foo9 b/sm2/nested/foo9
|
|
|
|
deleted file mode 100644
|
|
|
|
index 9c3b4f6..0000000
|
|
|
|
--- a/sm2/nested/foo9
|
|
|
|
+++ /dev/null
|
|
|
|
@@ -1 +0,0 @@
|
|
|
|
-foo9
|
|
|
|
EOF
|
|
|
|
git diff --submodule=diff >actual 2>err &&
|
|
|
|
test_must_be_empty err &&
|
|
|
|
diff_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
mv sm2-bak sm2
|
|
|
|
|
2016-08-31 23:27:25 +00:00
|
|
|
test_done
|