Skip to content

Commit

Permalink
tests: use test_cmp instead of piping to diff(1)
Browse files Browse the repository at this point in the history
Change submodule tests that piped to diff(1) to use test_cmp. The
resulting unified diff is easier to read.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Ævar Arnfjörð Bjarmason authored and Junio C Hamano committed Nov 14, 2010
1 parent 5649bd9 commit f8d186b
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 47 deletions.
96 changes: 64 additions & 32 deletions t/t4041-diff-submodule-option.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,43 +37,47 @@ head1=$(add_file sm1 foo1 foo2)
test_expect_success 'added submodule' "
git add sm1 &&
git diff-index -p --submodule=log HEAD >actual &&
diff actual - <<-EOF
cat >expected <<-EOF &&
Submodule sm1 0000000...$head1 (new submodule)
EOF
test_cmp expected actual
"

commit_file sm1 &&
head2=$(add_file sm1 foo3)

test_expect_success 'modified submodule(forward)' "
git diff-index -p --submodule=log HEAD >actual &&
diff actual - <<-EOF
cat >expected <<-EOF &&
Submodule sm1 $head1..$head2:
> Add foo3
EOF
test_cmp expected actual
"

test_expect_success 'modified submodule(forward)' "
git diff --submodule=log >actual &&
diff actual - <<-EOF
cat >expected <<-EOF &&
Submodule sm1 $head1..$head2:
> Add foo3
EOF
test_cmp expected actual
"

test_expect_success 'modified submodule(forward) --submodule' "
git diff --submodule >actual &&
diff actual - <<-EOF
cat >expected <<-EOF &&
Submodule sm1 $head1..$head2:
> Add foo3
EOF
test_cmp expected actual
"

fullhead1=$(cd sm1; git rev-list --max-count=1 $head1)
fullhead2=$(cd sm1; git rev-list --max-count=1 $head2)
test_expect_success 'modified submodule(forward) --submodule=short' "
git diff --submodule=short >actual &&
diff actual - <<-EOF
cat >expected <<-EOF &&
diff --git a/sm1 b/sm1
index $head1..$head2 160000
--- a/sm1
Expand All @@ -82,6 +86,7 @@ index $head1..$head2 160000
-Subproject commit $fullhead1
+Subproject commit $fullhead2
EOF
test_cmp expected actual
"

commit_file sm1 &&
Expand All @@ -93,24 +98,26 @@ head3=$(

test_expect_success 'modified submodule(backward)' "
git diff-index -p --submodule=log HEAD >actual &&
diff actual - <<-EOF
cat >expected <<-EOF &&
Submodule sm1 $head2..$head3 (rewind):
< Add foo3
< Add foo2
EOF
test_cmp expected actual
"

head4=$(add_file sm1 foo4 foo5) &&
head4_full=$(GIT_DIR=sm1/.git git rev-parse --verify HEAD)
test_expect_success 'modified submodule(backward and forward)' "
git diff-index -p --submodule=log HEAD >actual &&
diff actual - <<-EOF
cat >expected <<-EOF &&
Submodule sm1 $head2...$head4:
> Add foo5
> Add foo4
< Add foo3
< Add foo2
EOF
test_cmp expected actual
"

commit_file sm1 &&
Expand All @@ -123,7 +130,7 @@ mv sm1-bak sm1

test_expect_success 'typechanged submodule(submodule->blob), --cached' "
git diff --submodule=log --cached >actual &&
diff actual - <<-EOF
cat >expected <<-EOF &&
Submodule sm1 41fbea9...0000000 (submodule deleted)
diff --git a/sm1 b/sm1
new file mode 100644
Expand All @@ -133,11 +140,12 @@ index 0000000..9da5fb8
@@ -0,0 +1 @@
+sm1
EOF
test_cmp expected actual
"

test_expect_success 'typechanged submodule(submodule->blob)' "
git diff --submodule=log >actual &&
diff actual - <<-EOF
cat >expected <<-EOF &&
diff --git a/sm1 b/sm1
deleted file mode 100644
index 9da5fb8..0000000
Expand All @@ -147,13 +155,14 @@ index 9da5fb8..0000000
-sm1
Submodule sm1 0000000...$head4 (new submodule)
EOF
test_cmp expected actual
"

rm -rf sm1 &&
git checkout-index sm1
test_expect_success 'typechanged submodule(submodule->blob)' "
git diff-index -p --submodule=log HEAD >actual &&
diff actual - <<-EOF
cat >expected <<-EOF &&
Submodule sm1 $head4...0000000 (submodule deleted)
diff --git a/sm1 b/sm1
new file mode 100644
Expand All @@ -163,6 +172,7 @@ index 0000000..$head5
@@ -0,0 +1 @@
+sm1
EOF
test_cmp expected actual
"

rm -f sm1 &&
Expand All @@ -171,15 +181,16 @@ head6=$(add_file sm1 foo6 foo7)
fullhead6=$(cd sm1; git rev-list --max-count=1 $head6)
test_expect_success 'nonexistent commit' "
git diff-index -p --submodule=log HEAD >actual &&
diff actual - <<-EOF
cat >expected <<-EOF &&
Submodule sm1 $head4...$head6 (commits not present)
EOF
test_cmp expected actual
"

commit_file
test_expect_success 'typechanged submodule(blob->submodule)' "
git diff-index -p --submodule=log HEAD >actual &&
diff actual - <<-EOF
cat >expected <<-EOF &&
diff --git a/sm1 b/sm1
deleted file mode 100644
index $head5..0000000
Expand All @@ -189,21 +200,24 @@ index $head5..0000000
-sm1
Submodule sm1 0000000...$head6 (new submodule)
EOF
test_cmp expected actual
"

commit_file sm1 &&
test_expect_success 'submodule is up to date' "
git diff-index -p --submodule=log HEAD >actual &&
diff actual - <<-EOF
cat >expected <<-EOF &&
EOF
test_cmp expected actual
"

test_expect_success 'submodule contains untracked content' "
echo new > sm1/new-file &&
git diff-index -p --submodule=log HEAD >actual &&
diff actual - <<-EOF
cat >expected <<-EOF &&
Submodule sm1 contains untracked content
EOF
test_cmp expected actual
"

test_expect_success 'submodule contains untracked content (untracked ignored)' "
Expand All @@ -224,18 +238,20 @@ test_expect_success 'submodule contains untracked content (all ignored)' "
test_expect_success 'submodule contains untracked and modifed content' "
echo new > sm1/foo6 &&
git diff-index -p --submodule=log HEAD >actual &&
diff actual - <<-EOF
cat >expected <<-EOF &&
Submodule sm1 contains untracked content
Submodule sm1 contains modified content
EOF
test_cmp expected actual
"

test_expect_success 'submodule contains untracked and modifed content (untracked ignored)' "
echo new > sm1/foo6 &&
git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
diff actual - <<-EOF
cat >expected <<-EOF &&
Submodule sm1 contains modified content
EOF
test_cmp expected actual
"

test_expect_success 'submodule contains untracked and modifed content (dirty ignored)' "
Expand All @@ -253,45 +269,50 @@ test_expect_success 'submodule contains untracked and modifed content (all ignor
test_expect_success 'submodule contains modifed content' "
rm -f sm1/new-file &&
git diff-index -p --submodule=log HEAD >actual &&
diff actual - <<-EOF
cat >expected <<-EOF &&
Submodule sm1 contains modified content
EOF
test_cmp expected actual
"

(cd sm1; git commit -mchange foo6 >/dev/null) &&
head8=$(cd sm1; git rev-parse --verify HEAD | cut -c1-7) &&
test_expect_success 'submodule is modified' "
git diff-index -p --submodule=log HEAD >actual &&
diff actual - <<-EOF
cat >expected <<-EOF &&
Submodule sm1 $head6..$head8:
> change
EOF
test_cmp expected actual
"

test_expect_success 'modified submodule contains untracked content' "
echo new > sm1/new-file &&
git diff-index -p --submodule=log HEAD >actual &&
diff actual - <<-EOF
cat >expected <<-EOF &&
Submodule sm1 contains untracked content
Submodule sm1 $head6..$head8:
> change
EOF
test_cmp expected actual
"

test_expect_success 'modified submodule contains untracked content (untracked ignored)' "
git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
diff actual - <<-EOF
cat >expected <<-EOF &&
Submodule sm1 $head6..$head8:
> change
EOF
test_cmp expected actual
"

test_expect_success 'modified submodule contains untracked content (dirty ignored)' "
git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
diff actual - <<-EOF
cat >expected <<-EOF &&
Submodule sm1 $head6..$head8:
> change
EOF
test_cmp expected actual
"

test_expect_success 'modified submodule contains untracked content (all ignored)' "
Expand All @@ -302,31 +323,34 @@ test_expect_success 'modified submodule contains untracked content (all ignored)
test_expect_success 'modified submodule contains untracked and modifed content' "
echo modification >> sm1/foo6 &&
git diff-index -p --submodule=log HEAD >actual &&
diff actual - <<-EOF
cat >expected <<-EOF &&
Submodule sm1 contains untracked content
Submodule sm1 contains modified content
Submodule sm1 $head6..$head8:
> change
EOF
test_cmp expected actual
"

test_expect_success 'modified submodule contains untracked and modifed content (untracked ignored)' "
echo modification >> sm1/foo6 &&
git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
diff actual - <<-EOF
cat >expected <<-EOF &&
Submodule sm1 contains modified content
Submodule sm1 $head6..$head8:
> change
EOF
test_cmp expected actual
"

test_expect_success 'modified submodule contains untracked and modifed content (dirty ignored)' "
echo modification >> sm1/foo6 &&
git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
diff actual - <<-EOF
cat >expected <<-EOF &&
Submodule sm1 $head6..$head8:
> change
EOF
test_cmp expected actual
"

test_expect_success 'modified submodule contains untracked and modifed content (all ignored)' "
Expand All @@ -338,19 +362,21 @@ test_expect_success 'modified submodule contains untracked and modifed content (
test_expect_success 'modified submodule contains modifed content' "
rm -f sm1/new-file &&
git diff-index -p --submodule=log HEAD >actual &&
diff actual - <<-EOF
cat >expected <<-EOF &&
Submodule sm1 contains modified content
Submodule sm1 $head6..$head8:
> change
EOF
test_cmp expected actual
"

rm -rf sm1
test_expect_success 'deleted submodule' "
git diff-index -p --submodule=log HEAD >actual &&
diff actual - <<-EOF
cat >expected <<-EOF &&
Submodule sm1 $head6...0000000 (submodule deleted)
EOF
test_cmp expected actual
"

test_create_repo sm2 &&
Expand All @@ -359,41 +385,45 @@ git add sm2

test_expect_success 'multiple submodules' "
git diff-index -p --submodule=log HEAD >actual &&
diff actual - <<-EOF
cat >expected <<-EOF &&
Submodule sm1 $head6...0000000 (submodule deleted)
Submodule sm2 0000000...$head7 (new submodule)
EOF
test_cmp expected actual
"

test_expect_success 'path filter' "
git diff-index -p --submodule=log HEAD sm2 >actual &&
diff actual - <<-EOF
cat >expected <<-EOF &&
Submodule sm2 0000000...$head7 (new submodule)
EOF
test_cmp expected actual
"

commit_file sm2
test_expect_success 'given commit' "
git diff-index -p --submodule=log HEAD^ >actual &&
diff actual - <<-EOF
cat >expected <<-EOF &&
Submodule sm1 $head6...0000000 (submodule deleted)
Submodule sm2 0000000...$head7 (new submodule)
EOF
test_cmp expected actual
"

test_expect_success 'given commit --submodule' "
git diff-index -p --submodule HEAD^ >actual &&
diff actual - <<-EOF
cat >expected <<-EOF &&
Submodule sm1 $head6...0000000 (submodule deleted)
Submodule sm2 0000000...$head7 (new submodule)
EOF
test_cmp expected actual
"

fullhead7=$(cd sm2; git rev-list --max-count=1 $head7)

test_expect_success 'given commit --submodule=short' "
git diff-index -p --submodule=short HEAD^ >actual &&
diff actual - <<-EOF
cat >expected <<-EOF &&
diff --git a/sm1 b/sm1
deleted file mode 160000
index $head6..0000000
Expand All @@ -409,6 +439,7 @@ index 0000000..$head7
@@ -0,0 +1 @@
+Subproject commit $fullhead7
EOF
test_cmp expected actual
"

test_expect_success 'setup .git file for sm2' '
Expand All @@ -420,10 +451,11 @@ test_expect_success 'setup .git file for sm2' '

test_expect_success 'diff --submodule with .git file' '
git diff --submodule HEAD^ >actual &&
diff actual - <<-EOF
cat >expected <<-EOF &&
Submodule sm1 $head6...0000000 (submodule deleted)
Submodule sm2 0000000...$head7 (new submodule)
EOF
test_cmp expected actual
'

test_done
Loading

0 comments on commit f8d186b

Please sign in to comment.