Merge branch 'pc/t2027-git-to-pipe-cleanup'

Having a git command on the upstream side of a pipe in a test
script will hide the exit status from the command, which may cause
us to fail to notice a breakage; rewrite tests in a script to avoid
this issue.

* pc/t2027-git-to-pipe-cleanup:
  t2027: avoid using pipes
This commit is contained in:
Junio C Hamano 2017-04-26 15:39:02 +09:00
commit da4c600730

View File

@ -20,7 +20,7 @@ test_expect_success 'rev-parse --git-common-dir on main worktree' '
test_expect_success 'rev-parse --git-path objects linked worktree' ' test_expect_success 'rev-parse --git-path objects linked worktree' '
echo "$(git rev-parse --show-toplevel)/.git/objects" >expect && echo "$(git rev-parse --show-toplevel)/.git/objects" >expect &&
test_when_finished "rm -rf linked-tree && git worktree prune" && test_when_finished "rm -rf linked-tree actual expect && git worktree prune" &&
git worktree add --detach linked-tree master && git worktree add --detach linked-tree master &&
git -C linked-tree rev-parse --git-path objects >actual && git -C linked-tree rev-parse --git-path objects >actual &&
test_cmp expect actual test_cmp expect actual
@ -28,19 +28,21 @@ test_expect_success 'rev-parse --git-path objects linked worktree' '
test_expect_success '"list" all worktrees from main' ' test_expect_success '"list" all worktrees from main' '
echo "$(git rev-parse --show-toplevel) $(git rev-parse --short HEAD) [$(git symbolic-ref --short HEAD)]" >expect && echo "$(git rev-parse --show-toplevel) $(git rev-parse --short HEAD) [$(git symbolic-ref --short HEAD)]" >expect &&
test_when_finished "rm -rf here && git worktree prune" && test_when_finished "rm -rf here out actual expect && git worktree prune" &&
git worktree add --detach here master && git worktree add --detach here master &&
echo "$(git -C here rev-parse --show-toplevel) $(git rev-parse --short HEAD) (detached HEAD)" >>expect && echo "$(git -C here rev-parse --show-toplevel) $(git rev-parse --short HEAD) (detached HEAD)" >>expect &&
git worktree list | sed "s/ */ /g" >actual && git worktree list >out &&
sed "s/ */ /g" <out >actual &&
test_cmp expect actual test_cmp expect actual
' '
test_expect_success '"list" all worktrees from linked' ' test_expect_success '"list" all worktrees from linked' '
echo "$(git rev-parse --show-toplevel) $(git rev-parse --short HEAD) [$(git symbolic-ref --short HEAD)]" >expect && echo "$(git rev-parse --show-toplevel) $(git rev-parse --short HEAD) [$(git symbolic-ref --short HEAD)]" >expect &&
test_when_finished "rm -rf here && git worktree prune" && test_when_finished "rm -rf here out actual expect && git worktree prune" &&
git worktree add --detach here master && git worktree add --detach here master &&
echo "$(git -C here rev-parse --show-toplevel) $(git rev-parse --short HEAD) (detached HEAD)" >>expect && echo "$(git -C here rev-parse --show-toplevel) $(git rev-parse --short HEAD) (detached HEAD)" >>expect &&
git -C here worktree list | sed "s/ */ /g" >actual && git -C here worktree list >out &&
sed "s/ */ /g" <out >actual &&
test_cmp expect actual test_cmp expect actual
' '
@ -49,7 +51,7 @@ test_expect_success '"list" all worktrees --porcelain' '
echo "HEAD $(git rev-parse HEAD)" >>expect && echo "HEAD $(git rev-parse HEAD)" >>expect &&
echo "branch $(git symbolic-ref HEAD)" >>expect && echo "branch $(git symbolic-ref HEAD)" >>expect &&
echo >>expect && echo >>expect &&
test_when_finished "rm -rf here && git worktree prune" && test_when_finished "rm -rf here actual expect && git worktree prune" &&
git worktree add --detach here master && git worktree add --detach here master &&
echo "worktree $(git -C here rev-parse --show-toplevel)" >>expect && echo "worktree $(git -C here rev-parse --show-toplevel)" >>expect &&
echo "HEAD $(git rev-parse HEAD)" >>expect && echo "HEAD $(git rev-parse HEAD)" >>expect &&
@ -69,16 +71,17 @@ test_expect_success 'bare repo setup' '
' '
test_expect_success '"list" all worktrees from bare main' ' test_expect_success '"list" all worktrees from bare main' '
test_when_finished "rm -rf there && git -C bare1 worktree prune" && test_when_finished "rm -rf there out actual expect && git -C bare1 worktree prune" &&
git -C bare1 worktree add --detach ../there master && git -C bare1 worktree add --detach ../there master &&
echo "$(pwd)/bare1 (bare)" >expect && echo "$(pwd)/bare1 (bare)" >expect &&
echo "$(git -C there rev-parse --show-toplevel) $(git -C there rev-parse --short HEAD) (detached HEAD)" >>expect && echo "$(git -C there rev-parse --show-toplevel) $(git -C there rev-parse --short HEAD) (detached HEAD)" >>expect &&
git -C bare1 worktree list | sed "s/ */ /g" >actual && git -C bare1 worktree list >out &&
sed "s/ */ /g" <out >actual &&
test_cmp expect actual test_cmp expect actual
' '
test_expect_success '"list" all worktrees --porcelain from bare main' ' test_expect_success '"list" all worktrees --porcelain from bare main' '
test_when_finished "rm -rf there && git -C bare1 worktree prune" && test_when_finished "rm -rf there actual expect && git -C bare1 worktree prune" &&
git -C bare1 worktree add --detach ../there master && git -C bare1 worktree add --detach ../there master &&
echo "worktree $(pwd)/bare1" >expect && echo "worktree $(pwd)/bare1" >expect &&
echo "bare" >>expect && echo "bare" >>expect &&
@ -92,11 +95,12 @@ test_expect_success '"list" all worktrees --porcelain from bare main' '
' '
test_expect_success '"list" all worktrees from linked with a bare main' ' test_expect_success '"list" all worktrees from linked with a bare main' '
test_when_finished "rm -rf there && git -C bare1 worktree prune" && test_when_finished "rm -rf there out actual expect && git -C bare1 worktree prune" &&
git -C bare1 worktree add --detach ../there master && git -C bare1 worktree add --detach ../there master &&
echo "$(pwd)/bare1 (bare)" >expect && echo "$(pwd)/bare1 (bare)" >expect &&
echo "$(git -C there rev-parse --show-toplevel) $(git -C there rev-parse --short HEAD) (detached HEAD)" >>expect && echo "$(git -C there rev-parse --show-toplevel) $(git -C there rev-parse --short HEAD) (detached HEAD)" >>expect &&
git -C there worktree list | sed "s/ */ /g" >actual && git -C there worktree list >out &&
sed "s/ */ /g" <out >actual &&
test_cmp expect actual test_cmp expect actual
' '
@ -118,9 +122,11 @@ test_expect_success 'broken main worktree still at the top' '
cd linked && cd linked &&
echo "worktree $(pwd)" >expected && echo "worktree $(pwd)" >expected &&
echo "ref: .broken" >../.git/HEAD && echo "ref: .broken" >../.git/HEAD &&
git worktree list --porcelain | head -n 3 >actual && git worktree list --porcelain >out &&
head -n 3 out >actual &&
test_cmp ../expected actual && test_cmp ../expected actual &&
git worktree list | head -n 1 >actual.2 && git worktree list >out &&
head -n 1 out >actual.2 &&
grep -F "(error)" actual.2 grep -F "(error)" actual.2
) )
' '
@ -134,7 +140,8 @@ test_expect_success 'linked worktrees are sorted' '
test_commit new && test_commit new &&
git worktree add ../first && git worktree add ../first &&
git worktree add ../second && git worktree add ../second &&
git worktree list --porcelain | grep ^worktree >actual git worktree list --porcelain >out &&
grep ^worktree out >actual
) && ) &&
cat >expected <<-EOF && cat >expected <<-EOF &&
worktree $(pwd)/sorted/main worktree $(pwd)/sorted/main