#!/bin/sh
#
# Copyright (c) 2009, Junio C Hamano
#
global test_description := ''log family learns --stdin''
source ./test-lib.sh
proc check {
for cmd in [rev-list "log --stat]"
{
for i in [@Argv]
{
printf "%s\n" $i
} >input &&
test_expect_success "check $cmd $ifsjoin(Argv)" '
git $cmd $(cat input) >expect &&
git $cmd --stdin actual &&
sed -e "s/^/input /" input &&
sed -e "s/^/output /" expect &&
test_cmp expect actual
'
}
}
global them := ''1 2 3 4 5 6 7''
test_expect_success setup '
(
for i in 0 $them
do
for j in $them
do
echo $i.$j >file-$j &&
git add file-$j || exit
done &&
test_tick &&
git commit -m $i || exit
done &&
for i in $them
do
git checkout -b side-$i master~$i &&
echo updated $i >file-$i &&
git add file-$i &&
test_tick &&
git commit -m side-$i || exit
done
)
'
check master
check side-1 ^side-4
check side-1 ^side-7 --
check side-1 ^side-7 -- file-1
check side-1 ^side-7 -- file-2
check side-3 ^side-4 -- file-3
check side-3 ^side-2
check side-3 ^side-2 -- file-1
test_expect_success 'not only --stdin' '
cat >expect <<-EOF &&
7
file-1
file-2
EOF
cat >input <<-EOF &&
^master^
--
file-2
EOF
git log --pretty=tformat:%s --name-only --stdin master -- file-1 \
actual &&
test_cmp expect actual
'
test_done
(CommandList
children: [
(Assignment
keyword: Assign_None
pairs: [
(assign_pair
lhs: (LhsName name:test_description)
op: Equal
rhs: {(SQ <"log family learns --stdin">)}
spids: [13]
)
]
spids: [13]
)
(C {(.)} {(./test-lib.sh)})
(FuncDef
name: check
body:
(BraceGroup
children: [
(ForEach
iter_name: cmd
iter_words: [{(rev-list)} {(DQ ("log --stat"))}]
do_arg_iter: False
body:
(DoGroup
children: [
(AndOr
children: [
(ForEach
iter_name: i
iter_words: [{(DQ ($ VSub_At "$@"))}]
do_arg_iter: False
body:
(DoGroup
children: [
(C {(printf)}
{(DQ ("%s") (EscapedLiteralPart token:))} {($ VSub_Name "$i")}
)
]
spids: [59 72]
)
redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(input)} spids:[74])]
spids: [53 -1]
)
(C {(test_expect_success)}
{(DQ ("check ") ($ VSub_Name "$cmd") (" ") ($ VSub_Star "$*"))}
{
(SQ <"\n"> <"\t\t\tgit $cmd $(cat input) >expect &&\n">
<"\t\t\tgit $cmd --stdin actual &&\n"> <"\t\t\tsed -e \"s/^/input /\" input &&\n"> <"\t\t\tsed -e \"s/^/output /\" expect &&\n">
<"\t\t\ttest_cmp expect actual\n"> <"\t\t">
)
}
)
]
op_id: Op_DAmp
)
]
spids: [45 100]
)
spids: [37 -1]
)
]
spids: [29]
)
spids: [24 28]
)
(Assignment
keyword: Assign_None
pairs: [(assign_pair lhs:(LhsName name:them) op:Equal rhs:{(SQ <"1 2 3 4 5 6 7">)} spids:[105])]
spids: [105]
)
(C {(test_expect_success)} {(setup)}
{
(SQ <"\n"> <"\t(\n"> <"\t\tfor i in 0 $them\n"> <"\t\tdo\n"> <"\t\t\tfor j in $them\n">
<"\t\t\tdo\n"> <"\t\t\t\techo $i.$j >file-$j &&\n"> <"\t\t\t\tgit add file-$j || exit\n"> <"\t\t\tdone &&\n">
<"\t\t\ttest_tick &&\n"> <"\t\t\tgit commit -m $i || exit\n"> <"\t\tdone &&\n"> <"\t\tfor i in $them\n"> <"\t\tdo\n">
<"\t\t\tgit checkout -b side-$i master~$i &&\n"> <"\t\t\techo updated $i >file-$i &&\n"> <"\t\t\tgit add file-$i &&\n"> <"\t\t\ttest_tick &&\n">
<"\t\t\tgit commit -m side-$i || exit\n"> <"\t\tdone\n"> <"\t)\n">
)
}
)
(C {(check)} {(master)})
(C {(check)} {(side-1)} {(Lit_Other "^") (side-4)})
(C {(check)} {(side-1)} {(Lit_Other "^") (side-7)} {(--)})
(C {(check)} {(side-1)} {(Lit_Other "^") (side-7)} {(--)} {(file-1)})
(C {(check)} {(side-1)} {(Lit_Other "^") (side-7)} {(--)} {(file-2)})
(C {(check)} {(side-3)} {(Lit_Other "^") (side-4)} {(--)} {(file-3)})
(C {(check)} {(side-3)} {(Lit_Other "^") (side-2)})
(C {(check)} {(side-3)} {(Lit_Other "^") (side-2)} {(--)} {(file-1)})
(C {(test_expect_success)} {(SQ <"not only --stdin">)}
{
(SQ <"\n"> <"\tcat >expect <<-EOF &&\n"> <"\t7\n"> <"\n"> <"\tfile-1\n"> <"\tfile-2\n"> <"\tEOF\n">
<"\tcat >input <<-EOF &&\n"> <"\t^master^\n"> <"\t--\n"> <"\tfile-2\n"> <"\tEOF\n">
<"\tgit log --pretty=tformat:%s --name-only --stdin master -- file-1 \\\n"> <"\t\tactual &&\n"> <"\ttest_cmp expect actual\n">
)
}
)
(C {(test_done)})
]
)