#!/bin/sh global test_description := ''read-tree D/F conflict corner cases'' source ./test-lib.sh source "$TEST_DIRECTORY"/lib-read-tree.sh proc maketree { shell { rm -f .git/index .git/index.lock && git clean -d -f -f -q -x && global name := $1 && shiftfor it in @Argv { global path := $[expr $it : '\([^:]*\)] && mkdir -p $[dirname $path] && echo $it >$path && git update-index --add $path || exit } && git tag $name $[git write-tree] } } proc settree { rm -f .git/index .git/index.lock && git clean -d -f -f -q -x && git read-tree $1 && git checkout-index -f -q -u -a && git update-index --refresh } proc checkindex { git ls-files -s | sed "s|^[0-7][0-7]* $_x40 \([0-3]\) |\1 |" >current && cat >expect && test_cmp expect current } test_expect_success setup ' maketree O-000 a/b-2/c/d a/b/c/d a/x && maketree A-000 a/b-2/c/d a/b/c/d a/x && maketree A-001 a/b-2/c/d a/b/c/d a/b/c/e a/x && maketree B-000 a/b-2/c/d a/b a/x && maketree O-010 t-0 t/1 t/2 t=3 && maketree A-010 t-0 t t=3 && maketree B-010 t/1: t=3: && maketree O-020 ds/dma/ioat.c ds/dma/ioat_dca.c && maketree A-020 ds/dma/ioat/Makefile ds/dma/ioat/registers.h && : ' test_expect_success '3-way (1)' ' settree A-000 && read_tree_u_must_succeed -m -u O-000 A-000 B-000 && checkindex <<-EOF 3 a/b 0 a/b-2/c/d 1 a/b/c/d 2 a/b/c/d 0 a/x EOF ' test_expect_success '3-way (2)' ' settree A-001 && read_tree_u_must_succeed -m -u O-000 A-001 B-000 && checkindex <<-EOF 3 a/b 0 a/b-2/c/d 1 a/b/c/d 2 a/b/c/d 2 a/b/c/e 0 a/x EOF ' test_expect_success '3-way (3)' ' settree A-010 && read_tree_u_must_succeed -m -u O-010 A-010 B-010 && checkindex <<-EOF 2 t 1 t-0 2 t-0 1 t/1 3 t/1 1 t/2 0 t=3 EOF ' test_expect_success '2-way (1)' ' settree O-020 && read_tree_u_must_succeed -m -u O-020 A-020 && checkindex <<-EOF 0 ds/dma/ioat/Makefile 0 ds/dma/ioat/registers.h EOF ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"read-tree D/F conflict corner cases">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (C {(.)} {(DQ ($ VSub_Name "$TEST_DIRECTORY")) (/lib-read-tree.sh)}) (FuncDef name: maketree body: (BraceGroup children: [ (Subshell child: (AndOr children: [ (C {(rm)} {(-f)} {(.git/index)} {(.git/index.lock)}) (AndOr children: [ (C {(git)} {(clean)} {(-d)} {(-f)} {(-f)} {(-q)} {(-x)}) (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:name) op: Equal rhs: {(DQ ($ VSub_Number "$1"))} spids: [61] ) ] spids: [61] ) (AndOr children: [ (C {(shift)}) (AndOr children: [ (ForEach iter_name: it do_arg_iter: True body: (DoGroup children: [ (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:path) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(expr)} {(DQ ($ VSub_Name "$it"))} {(Lit_Other ":")} {(SQ <"\\([^:]*\\)">)} ) ] ) left_token: spids: [83 95] ) } spids: [82] ) ] spids: [82] ) (AndOr children: [ (C {(mkdir)} {(-p)} { (CommandSubPart command_list: (CommandList children: [ (C {(dirname)} {(DQ ($ VSub_Name "$path"))} ) ] ) left_token: spids: [104 110] ) } ) (AndOr children: [ (SimpleCommand words: [{(echo)} {(DQ ($ VSub_Name "$it"))}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(DQ ($ VSub_Name "$path"))} spids: [121] ) ] ) (AndOr children: [ (C {(git)} {(update-index)} {(--add)} {(DQ ($ VSub_Name "$path"))} ) (C {(exit)}) ] op_id: Op_DPipe ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] spids: [79 144] ) spids: [-1 -1] ) (C {(git)} {(tag)} {(DQ ($ VSub_Name "$name"))} { (CommandSubPart command_list: (CommandList children: [(C {(git)} {(write-tree)})] ) left_token: spids: [157 161] ) } ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) spids: [30 164] ) ] spids: [27] ) spids: [22 26] ) (FuncDef name: settree body: (BraceGroup children: [ (AndOr children: [ (C {(rm)} {(-f)} {(.git/index)} {(.git/index.lock)}) (AndOr children: [ (C {(git)} {(clean)} {(-d)} {(-f)} {(-f)} {(-q)} {(-x)}) (AndOr children: [ (C {(git)} {(read-tree)} {(DQ ($ VSub_Number "$1"))}) (AndOr children: [ (C {(git)} {(checkout-index)} {(-f)} {(-q)} {(-u)} {(-a)}) (C {(git)} {(update-index)} {(--refresh)}) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] spids: [174] ) spids: [169 173] ) (FuncDef name: checkindex body: (BraceGroup children: [ (AndOr children: [ (Pipeline children: [ (C {(git)} {(ls-files)} {(-s)}) (SimpleCommand words: [ {(sed)} { (DQ ("s|^[0-7][0-7]* ") ($ VSub_Name "$_x40") (" ") (EscapedLiteralPart token: ) ("[0-3]") (EscapedLiteralPart token:) ("\t|") (EscapedLiteralPart token: ) (" |") ) } ] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(current)} spids:[271])] ) ] negated: False ) (AndOr children: [ (SimpleCommand words: [{(cat)}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(expect)} spids:[279])] ) (C {(test_cmp)} {(expect)} {(current)}) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] spids: [245] ) spids: [240 244] ) (C {(test_expect_success)} {(setup)} { (SQ <"\n"> <"\tmaketree O-000 a/b-2/c/d a/b/c/d a/x &&\n"> <"\tmaketree A-000 a/b-2/c/d a/b/c/d a/x &&\n"> <"\tmaketree A-001 a/b-2/c/d a/b/c/d a/b/c/e a/x &&\n"> <"\tmaketree B-000 a/b-2/c/d a/b a/x &&\n"> <"\n"> <"\tmaketree O-010 t-0 t/1 t/2 t=3 &&\n"> <"\tmaketree A-010 t-0 t t=3 &&\n"> <"\tmaketree B-010 t/1: t=3: &&\n"> <"\n"> <"\tmaketree O-020 ds/dma/ioat.c ds/dma/ioat_dca.c &&\n"> <"\tmaketree A-020 ds/dma/ioat/Makefile ds/dma/ioat/registers.h &&\n"> <"\t:\n"> ) } ) (C {(test_expect_success)} {(SQ <"3-way (1)">)} { (SQ <"\n"> <"\tsettree A-000 &&\n"> <"\tread_tree_u_must_succeed -m -u O-000 A-000 B-000 &&\n"> <"\tcheckindex <<-EOF\n"> <"\t3 a/b\n"> <"\t0 a/b-2/c/d\n"> <"\t1 a/b/c/d\n"> <"\t2 a/b/c/d\n"> <"\t0 a/x\n"> <"\tEOF\n"> ) } ) (C {(test_expect_success)} {(SQ <"3-way (2)">)} { (SQ <"\n"> <"\tsettree A-001 &&\n"> <"\tread_tree_u_must_succeed -m -u O-000 A-001 B-000 &&\n"> <"\tcheckindex <<-EOF\n"> <"\t3 a/b\n"> <"\t0 a/b-2/c/d\n"> <"\t1 a/b/c/d\n"> <"\t2 a/b/c/d\n"> <"\t2 a/b/c/e\n"> <"\t0 a/x\n"> <"\tEOF\n"> ) } ) (C {(test_expect_success)} {(SQ <"3-way (3)">)} { (SQ <"\n"> <"\tsettree A-010 &&\n"> <"\tread_tree_u_must_succeed -m -u O-010 A-010 B-010 &&\n"> <"\tcheckindex <<-EOF\n"> <"\t2 t\n"> <"\t1 t-0\n"> <"\t2 t-0\n"> <"\t1 t/1\n"> <"\t3 t/1\n"> <"\t1 t/2\n"> <"\t0 t=3\n"> <"\tEOF\n"> ) } ) (C {(test_expect_success)} {(SQ <"2-way (1)">)} { (SQ <"\n"> <"\tsettree O-020 &&\n"> <"\tread_tree_u_must_succeed -m -u O-020 A-020 &&\n"> <"\tcheckindex <<-EOF\n"> <"\t0 ds/dma/ioat/Makefile\n"> <"\t0 ds/dma/ioat/registers.h\n"> <"\tEOF\n"> ) } ) (C {(test_done)}) ] )