git/t/t7421-submodule-summary-add.sh
Shourya Shukla d79b145569 t7421: eliminate 'grep' check in t7421.4 for mingw compatibility
The 'grep' check in test 4 of t7421 resulted in the failure of t7421 on
Windows due to a different error message

    error: cannot spawn git: No such file or directory

instead of

    fatal: exec 'rev-parse': cd to 'my-subm' failed: No such file or directory

Tighten up the check to compute 'src_abbrev' by guarding the
'verify_submodule_committish()' call using `p->status !='D'`, so that
the former isn't called in case of non-existent submodule directory,
consequently, there is no such error message on any execution
environment. The same need not be implemented for 'dst_abbrev' and is
rather redundant since the conditional 'if (S_ISGITLINK(p->mod_dst))'
already guards the 'verify_submodule_committish()' when we have a
status of 'D'.

Therefore, eliminate the 'grep' check in t7421. Instead, verify the
absence of an error message by doing a 'test_must_be_empty' on the
file containing the error.

Reported-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Helped-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Mentored-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-27 11:47:10 -07:00

69 lines
1.8 KiB
Bash
Executable file

#!/bin/sh
#
# Copyright (C) 2020 Shourya Shukla
#
test_description='Summary support for submodules, adding them using git submodule add
This test script tries to verify the sanity of summary subcommand of git submodule
while making sure to add submodules using `git submodule add` instead of
`git add` as done in t7401.
'
. ./test-lib.sh
test_expect_success 'summary test environment setup' '
git init sm &&
test_commit -C sm "add file" file file-content file-tag &&
git submodule add ./sm my-subm &&
test_tick &&
git commit -m "add submodule"
'
test_expect_success 'submodule summary output for initialized submodule' '
test_commit -C sm "add file2" file2 file2-content file2-tag &&
git submodule update --remote &&
test_tick &&
git commit -m "update submodule" my-subm &&
git submodule summary HEAD^ >actual &&
rev1=$(git -C sm rev-parse --short HEAD^) &&
rev2=$(git -C sm rev-parse --short HEAD) &&
cat >expected <<-EOF &&
* my-subm ${rev1}...${rev2} (1):
> add file2
EOF
test_cmp expected actual
'
test_expect_success 'submodule summary output for deinitialized submodule' '
git submodule deinit my-subm &&
git submodule summary HEAD^ >actual &&
test_must_be_empty actual &&
git submodule update --init my-subm &&
git submodule summary HEAD^ >actual &&
rev1=$(git -C sm rev-parse --short HEAD^) &&
rev2=$(git -C sm rev-parse --short HEAD) &&
cat >expected <<-EOF &&
* my-subm ${rev1}...${rev2} (1):
> add file2
EOF
test_cmp expected actual
'
test_expect_success 'submodule summary output for submodules with changed paths' '
git mv my-subm subm &&
git commit -m "change submodule path" &&
rev=$(git -C sm rev-parse --short HEAD^) &&
git submodule summary HEAD^^ -- my-subm >actual 2>err &&
test_must_be_empty err &&
cat >expected <<-EOF &&
* my-subm ${rev}...0000000:
EOF
test_cmp expected actual
'
test_done