From: Jeff Hostetler <jeffhost@microsoft.com>
To: git@vger.kernel.org
Cc: git@jeffhostetler.com, peff@peff.net, gitster@pobox.com,
jeffhost@microsoft.com, Johannes.Schindelin@gmx.de
Subject: [PATCH v2 8/8] status: tests for --porcelain=v2
Date: Mon, 25 Jul 2016 15:25:50 -0400 [thread overview]
Message-ID: <1469474750-49075-9-git-send-email-jeffhost@microsoft.com> (raw)
In-Reply-To: <1469474750-49075-1-git-send-email-jeffhost@microsoft.com>
Unit tests for porcelain v2 status format.
Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
---
t/t7064-wtstatus-pv2.sh | 542 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 542 insertions(+)
create mode 100755 t/t7064-wtstatus-pv2.sh
diff --git a/t/t7064-wtstatus-pv2.sh b/t/t7064-wtstatus-pv2.sh
new file mode 100755
index 0000000..7a7f777
--- /dev/null
+++ b/t/t7064-wtstatus-pv2.sh
@@ -0,0 +1,542 @@
+#!/bin/sh
+
+test_description='git status --porcelain=v2
+
+This test exercises porcelain V2 output for git status.'
+
+
+. ./test-lib.sh
+
+test_expect_success setup '
+ test_tick &&
+ git config --local core.autocrlf false &&
+ echo x >file_x &&
+ echo y >file_y &&
+ echo z >file_z &&
+ mkdir dir1 &&
+ echo a >dir1/file_a &&
+ echo b >dir1/file_b
+'
+
+
+##################################################################
+## Confirm VVP output prior to initial commit.
+##################################################################
+
+test_expect_success pre_initial_commit_0 '
+ cat >expected <<-EOF &&
+ ## branch: (initial) master
+ ? actual
+ ? dir1/
+ ? expected
+ ? file_x
+ ? file_y
+ ? file_z
+ EOF
+
+ git status --porcelain=v2 --branch --ignored --untracked-files=normal >actual &&
+ test_cmp expected actual
+'
+
+
+test_expect_success pre_initial_commit_1 '
+ git add file_x file_y file_z dir1 &&
+ SHA_A=`git hash-object -t blob -- dir1/file_a` &&
+ SHA_B=`git hash-object -t blob -- dir1/file_b` &&
+ SHA_X=`git hash-object -t blob -- file_x` &&
+ SHA_Y=`git hash-object -t blob -- file_y` &&
+ SHA_Z=`git hash-object -t blob -- file_z` &&
+ SHA_ZERO=0000000000000000000000000000000000000000 &&
+
+ cat >expected <<-EOF &&
+ ## branch: (initial) master
+ c A. N... 000000 100644 100644 $SHA_ZERO $SHA_A R0 dir1/file_a
+ c A. N... 000000 100644 100644 $SHA_ZERO $SHA_B R0 dir1/file_b
+ c A. N... 000000 100644 100644 $SHA_ZERO $SHA_X R0 file_x
+ c A. N... 000000 100644 100644 $SHA_ZERO $SHA_Y R0 file_y
+ c A. N... 000000 100644 100644 $SHA_ZERO $SHA_Z R0 file_z
+ ? actual
+ ? expected
+ EOF
+
+ git status --porcelain=v2 --branch --ignored --untracked-files=all >actual &&
+ test_cmp expected actual
+'
+
+## Try -z on the above
+test_expect_success pre_initial_commit_2 '
+ cat >expected.lf <<-EOF &&
+ ## branch: (initial) master
+ c A. N... 000000 100644 100644 $SHA_ZERO $SHA_A R0 dir1/file_a
+ c A. N... 000000 100644 100644 $SHA_ZERO $SHA_B R0 dir1/file_b
+ c A. N... 000000 100644 100644 $SHA_ZERO $SHA_X R0 file_x
+ c A. N... 000000 100644 100644 $SHA_ZERO $SHA_Y R0 file_y
+ c A. N... 000000 100644 100644 $SHA_ZERO $SHA_Z R0 file_z
+ ? actual
+ ? expected
+ EOF
+ perl -pe y/\\012/\\000/ <expected.lf >expected &&
+ rm expected.lf &&
+
+ git status -z --porcelain=v2 --branch --ignored --untracked-files=all >actual &&
+ test_cmp expected actual
+'
+
+##################################################################
+## Create first commit. Confirm commit sha in new track header.
+## Then make some changes on top of it.
+##################################################################
+
+test_expect_success initial_commit_0 '
+ git commit -m initial &&
+ H0=`git rev-parse HEAD` &&
+ cat >expected <<-EOF &&
+ ## branch: $H0 master
+ ? actual
+ ? expected
+ EOF
+
+ git status --porcelain=v2 --branch --ignored --untracked-files=all >actual &&
+ test_cmp expected actual
+'
+
+
+test_expect_success initial_commit_1 '
+ echo x >>file_x &&
+ SHA_X1=`git hash-object -t blob -- file_x` &&
+ rm file_z &&
+ H0=`git rev-parse HEAD` &&
+
+ cat >expected <<-EOF &&
+ ## branch: $H0 master
+ c .M N... 100644 100644 100644 $SHA_X $SHA_X R0 file_x
+ c .D N... 100644 100644 000000 $SHA_Z $SHA_Z R0 file_z
+ ? actual
+ ? expected
+ EOF
+
+ git status --porcelain=v2 --branch --ignored --untracked-files=all >actual &&
+ test_cmp expected actual
+'
+
+
+test_expect_success initial_commit_2 '
+ git add file_x &&
+ git rm file_z &&
+ H0=`git rev-parse HEAD` &&
+
+ cat >expected <<-EOF &&
+ ## branch: $H0 master
+ c M. N... 100644 100644 100644 $SHA_X $SHA_X1 R0 file_x
+ c D. N... 100644 000000 000000 $SHA_Z $SHA_ZERO R0 file_z
+ ? actual
+ ? expected
+ EOF
+
+ git status --porcelain=v2 --branch --ignored --untracked-files=all >actual &&
+ test_cmp expected actual
+'
+
+
+test_expect_success initial_commit_3 '
+ git mv file_y renamed_y &&
+ H0=`git rev-parse HEAD` &&
+
+ cat >expected.q <<-EOF &&
+ ## branch: $H0 master
+ c M. N... 100644 100644 100644 $SHA_X $SHA_X1 R0 file_x
+ c D. N... 100644 000000 000000 $SHA_Z $SHA_ZERO R0 file_z
+ c R. N... 100644 100644 100644 $SHA_Y $SHA_Y R100 renamed_yQfile_y
+ ? actual
+ ? expected
+ EOF
+ q_to_tab <expected.q >expected &&
+ rm expected.q &&
+
+ git status --porcelain=v2 --branch --ignored --untracked-files=all >actual &&
+ test_cmp expected actual
+'
+
+
+##################################################################
+## Create second commit.
+##################################################################
+
+test_expect_success second_commit_0 '
+ git commit -m second &&
+ H1=`git rev-parse HEAD` &&
+
+ cat >expected <<-EOF &&
+ ## branch: $H1 master
+ ? actual
+ ? expected
+ EOF
+
+ git status --porcelain=v2 --branch --ignored --untracked-files=all >actual &&
+ test_cmp expected actual
+'
+
+
+##################################################################
+## Ignore a file
+##################################################################
+
+test_expect_success ignore_file_0 '
+ echo x.ign >.gitignore &&
+ echo "ignore me" >x.ign &&
+ H1=`git rev-parse HEAD` &&
+
+ cat >expected <<-EOF &&
+ ## branch: $H1 master
+ ? .gitignore
+ ? actual
+ ? expected
+ ! x.ign
+ EOF
+
+ git status --porcelain=v2 --branch --ignored --untracked-files=all >actual &&
+ rm x.ign &&
+ rm .gitignore &&
+ test_cmp expected actual
+'
+
+
+##################################################################
+## Create some conflicts.
+##################################################################
+
+test_expect_success conflict_AA '
+ git branch AA_A master &&
+ git checkout AA_A &&
+ echo "Branch AA_A" >conflict.txt &&
+ SHA_AA_A=`git hash-object -t blob -- conflict.txt` &&
+ git add conflict.txt &&
+ git commit -m "branch aa_a" &&
+
+ git branch AA_B master &&
+ git checkout AA_B &&
+ echo "Branch AA_B" >conflict.txt &&
+ SHA_AA_B=`git hash-object -t blob -- conflict.txt` &&
+ git add conflict.txt &&
+ git commit -m "branch aa_b" &&
+
+ git branch AA_M AA_B &&
+ git checkout AA_M &&
+ test_must_fail git merge AA_A &&
+
+ HM=`git rev-parse HEAD` &&
+
+ cat >expected <<-EOF &&
+ ## branch: $HM AA_M
+ u AA N... 000000 100644 100644 100644 $SHA_ZERO $SHA_AA_B $SHA_AA_A conflict.txt
+ ? actual
+ ? expected
+ EOF
+
+ git status --porcelain=v2 --branch --ignored --untracked-files=all >actual &&
+ git reset --hard &&
+ test_cmp expected actual
+'
+
+
+test_expect_success conflict_UU '
+ git branch UU_ANC master &&
+ git checkout UU_ANC &&
+ echo "Ancestor" >conflict.txt &&
+ SHA_UU_ANC=`git hash-object -t blob -- conflict.txt` &&
+ git add conflict.txt &&
+ git commit -m "UU_ANC" &&
+
+ git branch UU_A UU_ANC &&
+ git checkout UU_A &&
+ echo "Branch UU_A" >conflict.txt &&
+ SHA_UU_A=`git hash-object -t blob -- conflict.txt` &&
+ git add conflict.txt &&
+ git commit -m "branch uu_a" &&
+
+ git branch UU_B UU_ANC &&
+ git checkout UU_B &&
+ echo "Branch UU_B" >conflict.txt &&
+ SHA_UU_B=`git hash-object -t blob -- conflict.txt` &&
+ git add conflict.txt &&
+ git commit -m "branch uu_b" &&
+
+ git branch UU_M UU_B &&
+ git checkout UU_M &&
+ test_must_fail git merge UU_A &&
+
+ HM=`git rev-parse HEAD` &&
+
+ cat >expected <<-EOF &&
+ ## branch: $HM UU_M
+ u UU N... 100644 100644 100644 100644 $SHA_UU_ANC $SHA_UU_B $SHA_UU_A conflict.txt
+ ? actual
+ ? expected
+ EOF
+
+ git status --porcelain=v2 --branch --ignored --untracked-files=all >actual &&
+ git reset --hard &&
+ test_cmp expected actual
+'
+
+
+##################################################################
+## Test upstream fields in branch header
+##################################################################
+
+test_expect_success 'upstream_fields_0' '
+ git checkout master &&
+ git clone . sub_repo &&
+ (
+ ## Confirm local master tracks remote master.
+ cd sub_repo &&
+ HUF=`git rev-parse HEAD` &&
+
+ cat >expected <<-EOF &&
+ ## branch: $HUF master origin/master +0 -0
+ ? actual
+ ? expected
+ EOF
+
+ git status --porcelain=v2 --branch --ignored --untracked-files=all >actual &&
+ test_cmp expected actual &&
+
+ ## Test ahead/behind.
+ echo xyz >file_xyz &&
+ git add file_xyz &&
+ git commit -m xyz &&
+
+ HUF=`git rev-parse HEAD` &&
+
+ cat >expected <<-EOF &&
+ ## branch: $HUF master origin/master +1 -0
+ ? actual
+ ? expected
+ EOF
+
+ git status --porcelain=v2 --branch --ignored --untracked-files=all >actual &&
+ test_cmp expected actual &&
+
+ ## Test upstream-gone case. Fake this by pointing origin/master at
+ ## a non-existing commit.
+ OLD=`git rev-parse origin/master` &&
+ NEW=$SHA_ZERO &&
+ mv .git/packed-refs .git/old-packed-refs &&
+ sed "s/$OLD/$NEW/g" <.git/old-packed-refs >.git/packed-refs &&
+
+ HUF=`git rev-parse HEAD` &&
+
+ cat >expected <<-EOF &&
+ ## branch: $HUF master origin/master
+ ? actual
+ ? expected
+ EOF
+
+ git status --porcelain=v2 --branch --ignored --untracked-files=all >actual &&
+ test_cmp expected actual
+ ) &&
+ rm -rf sub_repo
+'
+
+
+##################################################################
+## Test submodule status flags.
+##################################################################
+
+test_expect_success 'submodule_flags_0' '
+ git checkout master &&
+ git clone . sub_repo &&
+ git clone . super_repo &&
+ ( cd super_repo &&
+ git submodule add ../sub_repo sub1 &&
+
+ ## Confirm stage/add of clean submodule.
+ HMOD=`git hash-object -t blob -- .gitmodules` &&
+ HSUP=`git rev-parse HEAD` &&
+ HSUB=$HSUP &&
+
+ cat >expected <<-EOF &&
+ ## branch: $HSUP master origin/master +0 -0
+ c A. N... 000000 100644 100644 $SHA_ZERO $HMOD R0 .gitmodules
+ c A. S... 000000 160000 160000 $SHA_ZERO $HSUB R0 sub1
+ ? actual
+ ? expected
+ EOF
+
+ git status --porcelain=v2 --branch --ignored --untracked-files=all >actual &&
+ test_cmp expected actual
+ )
+'
+
+test_expect_success 'submodule_flags_1' '
+ ( cd super_repo &&
+ ## Make some untracked dirt in the submodule.
+ ( cd sub1 &&
+ echo "dirt" >file_in_sub
+ ) &&
+
+ HMOD=`git hash-object -t blob -- .gitmodules` &&
+ HSUP=`git rev-parse HEAD` &&
+ HSUB=$HSUP &&
+
+ cat >expected <<-EOF &&
+ ## branch: $HSUP master origin/master +0 -0
+ c A. N... 000000 100644 100644 $SHA_ZERO $HMOD R0 .gitmodules
+ c AM S..U 000000 160000 160000 $SHA_ZERO $HSUB R0 sub1
+ ? actual
+ ? expected
+ EOF
+
+ git status --porcelain=v2 --branch --ignored --untracked-files=all >actual &&
+ test_cmp expected actual
+ )
+'
+
+test_expect_success 'submodule_flags_2' '
+ ( cd super_repo &&
+ ## Make some staged dirt in the submodule.
+ ( cd sub1 &&
+ git add file_in_sub
+ ) &&
+
+ HMOD=`git hash-object -t blob -- .gitmodules` &&
+ HSUP=`git rev-parse HEAD` &&
+ HSUB=$HSUP &&
+
+ cat >expected <<-EOF &&
+ ## branch: $HSUP master origin/master +0 -0
+ c A. N... 000000 100644 100644 $SHA_ZERO $HMOD R0 .gitmodules
+ c AM S.M. 000000 160000 160000 $SHA_ZERO $HSUB R0 sub1
+ ? actual
+ ? expected
+ EOF
+
+ git status --porcelain=v2 --branch --ignored --untracked-files=all >actual &&
+ test_cmp expected actual
+ )
+'
+
+test_expect_success 'submodule_flags_3' '
+ ( cd super_repo &&
+ ## Make some staged and unstaged dirt (on the same file) in the submodule.
+ ## This does not cause us to get S.MU (because the submodule does not report
+ ## a "?" line for the unstaged changes).
+ ( cd sub1 &&
+ echo "more dirt" >>file_in_sub
+ ) &&
+
+ HMOD=`git hash-object -t blob -- .gitmodules` &&
+ HSUP=`git rev-parse HEAD` &&
+ HSUB=$HSUP &&
+
+ cat >expected <<-EOF &&
+ ## branch: $HSUP master origin/master +0 -0
+ c A. N... 000000 100644 100644 $SHA_ZERO $HMOD R0 .gitmodules
+ c AM S.M. 000000 160000 160000 $SHA_ZERO $HSUB R0 sub1
+ ? actual
+ ? expected
+ EOF
+
+ git status --porcelain=v2 --branch --ignored --untracked-files=all >actual &&
+ test_cmp expected actual
+ )
+'
+
+test_expect_success 'submodule_flags_4' '
+ ( cd super_repo &&
+ ## Make some staged and untracked dirt (on different files) in the submodule.
+ ( cd sub1 &&
+ git add file_in_sub &&
+ echo "dirt" >>another_file_in_sub
+ ) &&
+
+ HMOD=`git hash-object -t blob -- .gitmodules` &&
+ HSUP=`git rev-parse HEAD` &&
+ HSUB=$HSUP &&
+
+ cat >expected <<-EOF &&
+ ## branch: $HSUP master origin/master +0 -0
+ c A. N... 000000 100644 100644 $SHA_ZERO $HMOD R0 .gitmodules
+ c AM S.MU 000000 160000 160000 $SHA_ZERO $HSUB R0 sub1
+ ? actual
+ ? expected
+ EOF
+
+ git status --porcelain=v2 --branch --ignored --untracked-files=all >actual &&
+ test_cmp expected actual
+ )
+'
+
+test_expect_success 'submodule_flags_5' '
+ ( cd super_repo &&
+ ## Make a new commit in the submodule.
+ ( cd sub1 &&
+ git add file_in_sub &&
+ rm -f another_file_in_sub &&
+ git commit -m "new commit"
+ ) &&
+
+ HMOD=`git hash-object -t blob -- .gitmodules` &&
+ HSUP=`git rev-parse HEAD` &&
+ HSUB=$HSUP &&
+
+ cat >expected <<-EOF &&
+ ## branch: $HSUP master origin/master +0 -0
+ c A. N... 000000 100644 100644 $SHA_ZERO $HMOD R0 .gitmodules
+ c AM SC.. 000000 160000 160000 $SHA_ZERO $HSUB R0 sub1
+ ? actual
+ ? expected
+ EOF
+
+ git status --porcelain=v2 --branch --ignored --untracked-files=all >actual &&
+ test_cmp expected actual
+ )
+'
+
+test_expect_success 'submodule_flags_6' '
+ ( cd super_repo &&
+ ## Commit the new submodule commit in the super.
+ git add sub1 &&
+ git commit -m "super commit" &&
+
+ HSUP=`git rev-parse HEAD` &&
+
+ cat >expected <<-EOF &&
+ ## branch: $HSUP master origin/master +1 -0
+ ? actual
+ ? expected
+ EOF
+
+ git status --porcelain=v2 --branch --ignored --untracked-files=all >actual &&
+ test_cmp expected actual
+ )
+'
+
+test_expect_success 'submodule_flags_7' '
+ ( cd super_repo &&
+ ## Make some untracked dirt in the submodule.
+ ( cd sub1 &&
+ echo "yet more dirt" >>file_in_sub
+ ) &&
+
+ HMOD=`git hash-object -t blob -- .gitmodules` &&
+ HSUP=`git rev-parse HEAD` &&
+ HSUB=`(cd sub1 && git rev-parse HEAD)` &&
+
+ cat >expected <<-EOF &&
+ ## branch: $HSUP master origin/master +1 -0
+ c .M S.M. 160000 160000 160000 $HSUB $HSUB R0 sub1
+ ? actual
+ ? expected
+ EOF
+
+ git status --porcelain=v2 --branch --ignored --untracked-files=all >actual &&
+ test_cmp expected actual
+ )
+'
+
+##################################################################
+## The end.
+##################################################################
+
+test_done
--
2.8.0.rc4.17.gac42084.dirty
next prev parent reply other threads:[~2016-07-25 19:29 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-25 19:25 [PATCH v2 0/8] status: V2 porcelain status Jeff Hostetler
2016-07-25 19:25 ` [PATCH v2 1/8] status: rename long-format print routines Jeff Hostetler
2016-07-25 19:25 ` [PATCH v2 2/8] status: cleanup API to wt_status_print Jeff Hostetler
2016-07-25 20:05 ` Junio C Hamano
2016-07-25 19:25 ` [PATCH v2 3/8] status: support --porcelain[=<version>] Jeff Hostetler
2016-07-25 19:51 ` Jakub Narębski
2016-07-25 19:25 ` [PATCH v2 4/8] status: per-file data collection for --porcelain=v2 Jeff Hostetler
2016-07-25 20:14 ` Junio C Hamano
2016-07-26 13:31 ` Jeff Hostetler
2016-07-25 19:25 ` [PATCH v2 5/8] status: print per-file porcelain v2 status data Jeff Hostetler
2016-07-25 20:23 ` Junio C Hamano
2016-07-26 13:53 ` Jeff Hostetler
2016-07-25 19:25 ` [PATCH v2 6/8] status: print branch info with --porcelain=v2 --branch Jeff Hostetler
2016-07-25 20:30 ` Junio C Hamano
2016-07-25 19:25 ` [PATCH v2 7/8] status: update git-status.txt for --porcelain=v2 Jeff Hostetler
2016-07-25 22:43 ` Jakub Narębski
2016-07-26 15:34 ` Johannes Schindelin
2016-07-26 19:42 ` Jeff Hostetler
2016-07-25 19:25 ` Jeff Hostetler [this message]
2016-07-26 16:07 ` [PATCH v2 8/8] status: tests " Johannes Schindelin
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=1469474750-49075-9-git-send-email-jeffhost@microsoft.com \
--to=jeffhost@microsoft.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@jeffhostetler.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.