#!/bin/sh # # Copyright (c) 2008 Ping Yin # global test_description := ''Summary support for submodules This test tries to verify the sanity of summary subcommand of git submodule. '' source ./test-lib.sh proc add_file { global sm := $1 shift global owd := $[pwd] cd $smfor name in @Argv { echo $name > $name && git add $name && test_tick && git commit -m "Add $name" } >/dev/null git rev-parse --verify HEAD | cut -c1-7 cd $owd } proc commit_file { test_tick && git commit @Argv -m "Commit $ifsjoin(Argv)" >/dev/null } test_create_repo sm1 && add_file . foo >/dev/null global head1 := $[add_file sm1 foo1 foo2] test_expect_success 'added submodule' " git add sm1 && git submodule summary >actual && cat >expected <<-EOF && * sm1 0000000...$head1 (2): > Add foo2 EOF test_cmp expected actual " test_expect_success 'added submodule (subdirectory)' " mkdir sub && ( cd sub && git submodule summary >../actual ) && cat >expected <<-EOF && * ../sm1 0000000...$head1 (2): > Add foo2 EOF test_cmp expected actual " test_expect_success 'added submodule (subdirectory only)' " ( cd sub && git submodule summary . >../actual ) && >expected && test_cmp expected actual " test_expect_success 'added submodule (subdirectory with explicit path)' " ( cd sub && git submodule summary ../sm1 >../actual ) && cat >expected <<-EOF && * ../sm1 0000000...$head1 (2): > Add foo2 EOF test_cmp expected actual " commit_file sm1 && global head2 := $[add_file sm1 foo3] test_expect_success 'modified submodule(forward)' " git submodule summary >actual && cat >expected <<-EOF && * sm1 $head1...$head2 (1): > Add foo3 EOF test_cmp expected actual " test_expect_success 'modified submodule(forward), --files' " git submodule summary --files >actual && cat >expected <<-EOF && * sm1 $head1...$head2 (1): > Add foo3 EOF test_cmp expected actual " test_expect_success 'no ignore=all setting has any effect' " git config -f .gitmodules submodule.sm1.path sm1 && git config -f .gitmodules submodule.sm1.ignore all && git config submodule.sm1.ignore all && git config diff.ignoreSubmodules all && git submodule summary >actual && cat >expected <<-EOF && * sm1 $head1...$head2 (1): > Add foo3 EOF test_cmp expected actual && git config --unset diff.ignoreSubmodules && git config --remove-section submodule.sm1 && git config -f .gitmodules --remove-section submodule.sm1 " commit_file sm1 && global head3 := $[ cd sm1 && git reset --hard HEAD~2 >/dev/null && git rev-parse --verify HEAD | cut -c1-7] test_expect_success 'modified submodule(backward)' " git submodule summary >actual && cat >expected <<-EOF && * sm1 $head2...$head3 (2): < Add foo3 < Add foo2 EOF test_cmp expected actual " global head4 := $[add_file sm1 foo4 foo5] && global head4_full := $[env GIT_DIR=sm1/.git git rev-parse --verify HEAD] test_expect_success 'modified submodule(backward and forward)' " git submodule summary >actual && cat >expected <<-EOF && * sm1 $head2...$head4 (4): > Add foo5 > Add foo4 < Add foo3 < Add foo2 EOF test_cmp expected actual " test_expect_success '--summary-limit' " git submodule summary -n 3 >actual && cat >expected <<-EOF && * sm1 $head2...$head4 (4): > Add foo5 > Add foo4 < Add foo3 EOF test_cmp expected actual " commit_file sm1 && mv sm1 sm1-bak && echo sm1 >sm1 && global 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 submodule summary --cached >actual && cat >expected <<-EOF && * sm1 $head4(submodule)->$head5(blob) (3): < Add foo5 EOF test_i18ncmp actual expected " test_expect_success 'typechanged submodule(submodule->blob), --files' " git submodule summary --files >actual && cat >expected <<-EOF && * sm1 $head5(blob)->$head4(submodule) (3): > Add foo5 EOF test_i18ncmp actual expected " rm -rf sm1 && git checkout-index sm1 test_expect_success 'typechanged submodule(submodule->blob)' " git submodule summary >actual && cat >expected <<-EOF && * sm1 $head4(submodule)->$head5(blob): EOF test_i18ncmp actual expected " rm -f sm1 && test_create_repo sm1 && global head6 := $[add_file sm1 foo6 foo7] test_expect_success 'nonexistent commit' " git submodule summary >actual && cat >expected <<-EOF && * sm1 $head4...$head6: Warn: sm1 doesn't contain commit $head4_full EOF test_i18ncmp actual expected " commit_file test_expect_success 'typechanged submodule(blob->submodule)' " git submodule summary >actual && cat >expected <<-EOF && * sm1 $head5(blob)->$head6(submodule) (2): > Add foo7 EOF test_i18ncmp expected actual " commit_file sm1 && rm -rf sm1 test_expect_success 'deleted submodule' " git submodule summary >actual && cat >expected <<-EOF && * sm1 $head6...0000000: EOF test_cmp expected actual " test_create_repo sm2 && global head7 := $[add_file sm2 foo8 foo9] && git add sm2 test_expect_success 'multiple submodules' " git submodule summary >actual && cat >expected <<-EOF && * sm1 $head6...0000000: * sm2 0000000...$head7 (2): > Add foo9 EOF test_cmp expected actual " test_expect_success 'path filter' " git submodule summary sm2 >actual && cat >expected <<-EOF && * sm2 0000000...$head7 (2): > Add foo9 EOF test_cmp expected actual " commit_file sm2 test_expect_success 'given commit' " git submodule summary HEAD^ >actual && cat >expected <<-EOF && * sm1 $head6...0000000: * sm2 0000000...$head7 (2): > Add foo9 EOF test_cmp expected actual " test_expect_success '--for-status' " git submodule summary --for-status HEAD^ >actual && test_i18ncmp actual - < Add foo9 EOF " test_expect_success 'fail when using --files together with --cached' " test_must_fail git submodule summary --files --cached " test_expect_success 'should not fail in an empty repo' " git init xyzzy && cd xyzzy && git submodule summary >output 2>&1 && test_cmp output /dev/null " test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: { (SQ <"Summary support for submodules\n"> <"\n"> <"This test tries to verify the sanity of summary subcommand of git submodule.\n"> ) } spids: [13] ) ] spids: [13] ) (C {(.)} {(./test-lib.sh)}) (FuncDef name: add_file body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:sm) op: Equal rhs: {($ VSub_Number "$1")} spids: [34] ) ] spids: [34] ) (C {(shift)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:owd) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(pwd)})]) left_token: spids: [42 44] ) } spids: [41] ) ] spids: [41] ) (C {(cd)} {(DQ ($ VSub_Name "$sm"))}) (ForEach iter_name: name do_arg_iter: True body: (DoGroup children: [ (AndOr children: [ (SimpleCommand words: [{(echo)} {(DQ ($ VSub_Name "$name"))}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(DQ ($ VSub_Name "$name"))} spids: [68] ) ] ) (AndOr children: [ (C {(git)} {(add)} {(DQ ($ VSub_Name "$name"))}) (AndOr children: [ (C {(test_tick)}) (C {(git)} {(commit)} {(-m)} {(DQ ("Add ") ($ VSub_Name "$name"))}) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] spids: [59 105] ) redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[107])] spids: [-1 -1] ) (Pipeline children: [(C {(git)} {(rev-parse)} {(--verify)} {(HEAD)}) (C {(cut)} {(-c1-7)})] negated: False ) (C {(cd)} {(DQ ($ VSub_Name "$owd"))}) ] spids: [31] ) spids: [26 30] ) (FuncDef name: commit_file body: (BraceGroup children: [ (AndOr children: [ (C {(test_tick)}) (SimpleCommand words: [ {(git)} {(commit)} {(DQ ($ VSub_At "$@"))} {(-m)} {(DQ ("Commit ") ($ VSub_Star "$*"))} ] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[162])] ) ] op_id: Op_DAmp ) ] spids: [139] ) spids: [134 138] ) (AndOr children: [ (C {(test_create_repo)} {(sm1)}) (SimpleCommand words: [{(add_file)} {(.)} {(foo)}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[180])] ) ] op_id: Op_DAmp ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:head1) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(add_file)} {(sm1)} {(foo1)} {(foo2)})]) left_token: spids: [185 193] ) } spids: [184] ) ] spids: [184] ) (C {(test_expect_success)} {(SQ <"added submodule">)} { (DQ ("\n") ("\tgit add sm1 &&\n") ("\tgit submodule summary >actual &&\n") ("\tcat >expected <<-EOF &&\n") ("* sm1 0000000...") ($ VSub_Name "$head1") (" (2):\n") (" > Add foo2\n") ("\n") ("EOF\n") ("\ttest_cmp expected actual\n") ) } ) (C {(test_expect_success)} {(SQ <"added submodule (subdirectory)">)} { (DQ ("\n") ("\tmkdir sub &&\n") ("\t(\n") ("\t\tcd sub &&\n") ("\t\tgit submodule summary >../actual\n") ("\t) &&\n") ("\tcat >expected <<-EOF &&\n") ("* ../sm1 0000000...") ($ VSub_Name "$head1") (" (2):\n") (" > Add foo2\n") ("\n") ("EOF\n") ("\ttest_cmp expected actual\n") ) } ) (C {(test_expect_success)} {(SQ <"added submodule (subdirectory only)">)} { (DQ ("\n") ("\t(\n") ("\t\tcd sub &&\n") ("\t\tgit submodule summary . >../actual\n") ("\t) &&\n") ("\t>expected &&\n") ("\ttest_cmp expected actual\n") ) } ) (C {(test_expect_success)} {(SQ <"added submodule (subdirectory with explicit path)">)} { (DQ ("\n") ("\t(\n") ("\t\tcd sub &&\n") ("\t\tgit submodule summary ../sm1 >../actual\n") ("\t) &&\n") ("\tcat >expected <<-EOF &&\n") ("* ../sm1 0000000...") ($ VSub_Name "$head1") (" (2):\n") (" > Add foo2\n") ("\n") ("EOF\n") ("\ttest_cmp expected actual\n") ) } ) (AndOr children: [ (C {(commit_file)} {(sm1)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:head2) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(add_file)} {(sm1)} {(foo3)})]) left_token: spids: [288 294] ) } spids: [287] ) ] spids: [287] ) ] op_id: Op_DAmp ) (C {(test_expect_success)} {(SQ <"modified submodule(forward)">)} { (DQ ("\n") ("\tgit submodule summary >actual &&\n") ("\tcat >expected <<-EOF &&\n") ("* sm1 ") ($ VSub_Name "$head1") (...) ($ VSub_Name "$head2") (" (1):\n") (" > Add foo3\n") ("\n") ("EOF\n") ("\ttest_cmp expected actual\n") ) } ) (C {(test_expect_success)} {(SQ <"modified submodule(forward), --files">)} { (DQ ("\n") ("\tgit submodule summary --files >actual &&\n") ("\tcat >expected <<-EOF &&\n") ("* sm1 ") ($ VSub_Name "$head1") (...) ($ VSub_Name "$head2") (" (1):\n") (" > Add foo3\n") ("\n") ("EOF\n") ("\ttest_cmp expected actual\n") ) } ) (C {(test_expect_success)} {(SQ <"no ignore=all setting has any effect">)} { (DQ ("\n") ("\tgit config -f .gitmodules submodule.sm1.path sm1 &&\n") ("\tgit config -f .gitmodules submodule.sm1.ignore all &&\n") ("\tgit config submodule.sm1.ignore all &&\n") ("\tgit config diff.ignoreSubmodules all &&\n") ("\tgit submodule summary >actual &&\n") ("\tcat >expected <<-EOF &&\n") ("* sm1 ") ($ VSub_Name "$head1") (...) ($ VSub_Name "$head2") (" (1):\n") (" > Add foo3\n") ("\n") ("EOF\n") ("\ttest_cmp expected actual &&\n") ("\tgit config --unset diff.ignoreSubmodules &&\n") ("\tgit config --remove-section submodule.sm1 &&\n") ("\tgit config -f .gitmodules --remove-section submodule.sm1\n") ) } ) (AndOr children: [ (C {(commit_file)} {(sm1)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:head3) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (AndOr children: [ (C {(cd)} {(sm1)}) (AndOr children: [ (SimpleCommand words: [{(git)} {(reset)} {(--hard)} {(HEAD) (Lit_Tilde "~") (2)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [398] ) ] ) (Pipeline children: [ (C {(git)} {(rev-parse)} {(--verify)} {(HEAD)}) (C {(cut)} {(-c1-7)}) ] negated: False ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] ) left_token: spids: [378 418] ) } spids: [377] ) ] spids: [377] ) ] op_id: Op_DAmp ) (C {(test_expect_success)} {(SQ <"modified submodule(backward)">)} { (DQ ("\n") ("\tgit submodule summary >actual &&\n") ("\tcat >expected <<-EOF &&\n") ("* sm1 ") ($ VSub_Name "$head2") (...) ($ VSub_Name "$head3") (" (2):\n") (" < Add foo3\n") (" < Add foo2\n") ("\n") ("EOF\n") ("\ttest_cmp expected actual\n") ) } ) (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:head4) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(add_file)} {(sm1)} {(foo4)} {(foo5)})]) left_token: spids: [445 453] ) } spids: [444] ) ] spids: [444] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:head4_full) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (SimpleCommand words: [{(git)} {(rev-parse)} {(--verify)} {(HEAD)}] more_env: [(env_pair name:GIT_DIR val:{(sm1/.git)} spids:[459])] ) ] ) left_token: spids: [458 469] ) } spids: [457] ) ] spids: [457] ) ] op_id: Op_DAmp ) (C {(test_expect_success)} {(SQ <"modified submodule(backward and forward)">)} { (DQ ("\n") ("\tgit submodule summary >actual &&\n") ("\tcat >expected <<-EOF &&\n") ("* sm1 ") ($ VSub_Name "$head2") (...) ($ VSub_Name "$head4") (" (4):\n") (" > Add foo5\n") (" > Add foo4\n") (" < Add foo3\n") (" < Add foo2\n") ("\n") ("EOF\n") ("\ttest_cmp expected actual\n") ) } ) (C {(test_expect_success)} {(SQ <--summary-limit>)} { (DQ ("\n") ("\tgit submodule summary -n 3 >actual &&\n") ("\tcat >expected <<-EOF &&\n") ("* sm1 ") ($ VSub_Name "$head2") (...) ($ VSub_Name "$head4") (" (4):\n") (" > Add foo5\n") (" > Add foo4\n") (" < Add foo3\n") ("\n") ("EOF\n") ("\ttest_cmp expected actual\n") ) } ) (AndOr children: [ (C {(commit_file)} {(sm1)}) (AndOr children: [ (C {(mv)} {(sm1)} {(sm1-bak)}) (AndOr children: [ (SimpleCommand words: [{(echo)} {(sm1)}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(sm1)} spids:[538])] ) (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:head5) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(git)} {(hash-object)} {(sm1)}) (C {(cut)} {(-c1-7)}) ] negated: False ) ] ) left_token: spids: [544 556] ) } spids: [543] ) ] spids: [543] ) (AndOr children: [ (C {(git)} {(add)} {(sm1)}) (AndOr children: [(C {(rm)} {(-f)} {(sm1)}) (C {(mv)} {(sm1-bak)} {(sm1)})] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) (C {(test_expect_success)} {(SQ <"typechanged submodule(submodule->blob), --cached">)} { (DQ ("\n") ("\tgit submodule summary --cached >actual &&\n") ("\tcat >expected <<-EOF &&\n") ("* sm1 ") ($ VSub_Name "$head4") ("(submodule)->") ($ VSub_Name "$head5") ("(blob) (3):\n") (" < Add foo5\n") ("\n") ("EOF\n") ("\ttest_i18ncmp actual expected\n") ) } ) (C {(test_expect_success)} {(SQ <"typechanged submodule(submodule->blob), --files">)} { (DQ ("\n") ("\tgit submodule summary --files >actual &&\n") ("\tcat >expected <<-EOF &&\n") ("* sm1 ") ($ VSub_Name "$head5") ("(blob)->") ($ VSub_Name "$head4") ("(submodule) (3):\n") (" > Add foo5\n") ("\n") ("EOF\n") ("\ttest_i18ncmp actual expected\n") ) } ) (AndOr children: [(C {(rm)} {(-rf)} {(sm1)}) (C {(git)} {(checkout-index)} {(sm1)})] op_id: Op_DAmp ) (C {(test_expect_success)} {(SQ <"typechanged submodule(submodule->blob)">)} { (DQ ("\n") ("\tgit submodule summary >actual &&\n") ("\tcat >expected <<-EOF &&\n") ("* sm1 ") ($ VSub_Name "$head4") ("(submodule)->") ($ VSub_Name "$head5") ("(blob):\n") ("\n") ("EOF\n") ("\ttest_i18ncmp actual expected\n") ) } ) (AndOr children: [ (C {(rm)} {(-f)} {(sm1)}) (AndOr children: [ (C {(test_create_repo)} {(sm1)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:head6) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [(C {(add_file)} {(sm1)} {(foo6)} {(foo7)})] ) left_token: spids: [677 685] ) } spids: [676] ) ] spids: [676] ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) (C {(test_expect_success)} {(SQ <"nonexistent commit">)} { (DQ ("\n") ("\tgit submodule summary >actual &&\n") ("\tcat >expected <<-EOF &&\n") ("* sm1 ") ($ VSub_Name "$head4") (...) ($ VSub_Name "$head6") (":\n") (" Warn: sm1 doesn't contain commit ") ($ VSub_Name "$head4_full") ("\n") ("\n") ("EOF\n") ("\ttest_i18ncmp actual expected\n") ) } ) (C {(commit_file)}) (C {(test_expect_success)} {(SQ <"typechanged submodule(blob->submodule)">)} { (DQ ("\n") ("\tgit submodule summary >actual &&\n") ("\tcat >expected <<-EOF &&\n") ("* sm1 ") ($ VSub_Name "$head5") ("(blob)->") ($ VSub_Name "$head6") ("(submodule) (2):\n") (" > Add foo7\n") ("\n") ("EOF\n") ("\ttest_i18ncmp expected actual\n") ) } ) (AndOr children:[(C {(commit_file)} {(sm1)})(C {(rm)} {(-rf)} {(sm1)})] op_id:Op_DAmp) (C {(test_expect_success)} {(SQ <"deleted submodule">)} { (DQ ("\n") ("\tgit submodule summary >actual &&\n") ("\tcat >expected <<-EOF &&\n") ("* sm1 ") ($ VSub_Name "$head6") ("...0000000:\n") ("\n") ("EOF\n") ("\ttest_cmp expected actual\n") ) } ) (AndOr children: [ (C {(test_create_repo)} {(sm2)}) (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:head7) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [(C {(add_file)} {(sm2)} {(foo8)} {(foo9)})] ) left_token: spids: [773 781] ) } spids: [772] ) ] spids: [772] ) (C {(git)} {(add)} {(sm2)}) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) (C {(test_expect_success)} {(SQ <"multiple submodules">)} { (DQ ("\n") ("\tgit submodule summary >actual &&\n") ("\tcat >expected <<-EOF &&\n") ("* sm1 ") ($ VSub_Name "$head6") ("...0000000:\n") ("\n") ("* sm2 0000000...") ($ VSub_Name "$head7") (" (2):\n") (" > Add foo9\n") ("\n") ("EOF\n") ("\ttest_cmp expected actual\n") ) } ) (C {(test_expect_success)} {(SQ <"path filter">)} { (DQ ("\n") ("\tgit submodule summary sm2 >actual &&\n") ("\tcat >expected <<-EOF &&\n") ("* sm2 0000000...") ($ VSub_Name "$head7") (" (2):\n") (" > Add foo9\n") ("\n") ("EOF\n") ("\ttest_cmp expected actual\n") ) } ) (C {(commit_file)} {(sm2)}) (C {(test_expect_success)} {(SQ <"given commit">)} { (DQ ("\n") ("\tgit submodule summary HEAD^ >actual &&\n") ("\tcat >expected <<-EOF &&\n") ("* sm1 ") ($ VSub_Name "$head6") ("...0000000:\n") ("\n") ("* sm2 0000000...") ($ VSub_Name "$head7") (" (2):\n") (" > Add foo9\n") ("\n") ("EOF\n") ("\ttest_cmp expected actual\n") ) } ) (C {(test_expect_success)} {(SQ <--for-status>)} { (DQ ("\n") ("\tgit submodule summary --for-status HEAD^ >actual &&\n") ("\ttest_i18ncmp actual - < Add foo9\n") ("\n") ("EOF\n") ) } ) (C {(test_expect_success)} {(SQ <"fail when using --files together with --cached">)} {(DQ ("\n") ("\ttest_must_fail git submodule summary --files --cached\n"))} ) (C {(test_expect_success)} {(SQ <"should not fail in an empty repo">)} { (DQ ("\n") ("\tgit init xyzzy &&\n") ("\tcd xyzzy &&\n") ("\tgit submodule summary >output 2>&1 &&\n") ("\ttest_cmp output /dev/null\n") ) } ) (C {(test_done)}) ] )