t / t4056-diff-order.shon commit Merge branch 'rs/copy-array' into maint (90334a8)
   1#!/bin/sh
   2
   3test_description='diff order'
   4
   5. ./test-lib.sh
   6
   7create_files () {
   8        echo "$1" >a.h &&
   9        echo "$1" >b.c &&
  10        echo "$1" >c/Makefile &&
  11        echo "$1" >d.txt &&
  12        git add a.h b.c c/Makefile d.txt &&
  13        git commit -m"$1"
  14}
  15
  16test_expect_success 'setup' '
  17        mkdir c &&
  18        create_files 1 &&
  19        create_files 2 &&
  20
  21        cat >order_file_1 <<-\EOF &&
  22        *Makefile
  23        *.txt
  24        *.h
  25        EOF
  26
  27        cat >order_file_2 <<-\EOF &&
  28        *Makefile
  29        *.h
  30        *.c
  31        EOF
  32
  33        cat >expect_none <<-\EOF &&
  34        a.h
  35        b.c
  36        c/Makefile
  37        d.txt
  38        EOF
  39
  40        cat >expect_1 <<-\EOF &&
  41        c/Makefile
  42        d.txt
  43        a.h
  44        b.c
  45        EOF
  46
  47        cat >expect_2 <<-\EOF
  48        c/Makefile
  49        a.h
  50        b.c
  51        d.txt
  52        EOF
  53'
  54
  55test_expect_success "no order (=tree object order)" '
  56        git diff --name-only HEAD^..HEAD >actual &&
  57        test_cmp expect_none actual
  58'
  59
  60test_expect_success 'missing orderfile' '
  61        rm -f bogus_file &&
  62        test_must_fail git diff -Obogus_file --name-only HEAD^..HEAD
  63'
  64
  65test_expect_success POSIXPERM,SANITY 'unreadable orderfile' '
  66        >unreadable_file &&
  67        chmod -r unreadable_file &&
  68        test_must_fail git diff -Ounreadable_file --name-only HEAD^..HEAD
  69'
  70
  71test_expect_success "orderfile using option from subdir with --output" '
  72        mkdir subdir &&
  73        git -C subdir diff -O../order_file_1 --output ../actual --name-only HEAD^..HEAD &&
  74        test_cmp expect_1 actual
  75'
  76
  77for i in 1 2
  78do
  79        test_expect_success "orderfile using option ($i)" '
  80                git diff -Oorder_file_$i --name-only HEAD^..HEAD >actual &&
  81                test_cmp expect_$i actual
  82        '
  83
  84        test_expect_success PIPE "orderfile is fifo ($i)" '
  85                rm -f order_fifo &&
  86                mkfifo order_fifo &&
  87                {
  88                        cat order_file_$i >order_fifo &
  89                } &&
  90                git diff -O order_fifo --name-only HEAD^..HEAD >actual &&
  91                wait &&
  92                test_cmp expect_$i actual
  93        '
  94
  95        test_expect_success "orderfile using config ($i)" '
  96                git -c diff.orderfile=order_file_$i diff --name-only HEAD^..HEAD >actual &&
  97                test_cmp expect_$i actual
  98        '
  99
 100        test_expect_success "cancelling configured orderfile ($i)" '
 101                git -c diff.orderfile=order_file_$i diff -O/dev/null --name-only HEAD^..HEAD >actual &&
 102                test_cmp expect_none actual
 103        '
 104done
 105
 106test_expect_success 'setup for testing combine-diff order' '
 107        git checkout -b tmp HEAD~ &&
 108        create_files 3 &&
 109        git checkout master &&
 110        git merge --no-commit -s ours tmp &&
 111        create_files 5
 112'
 113
 114test_expect_success "combine-diff: no order (=tree object order)" '
 115        git diff --name-only HEAD HEAD^ HEAD^2 >actual &&
 116        test_cmp expect_none actual
 117'
 118
 119for i in 1 2
 120do
 121        test_expect_success "combine-diff: orderfile using option ($i)" '
 122                git diff -Oorder_file_$i --name-only HEAD HEAD^ HEAD^2 >actual &&
 123                test_cmp expect_$i actual
 124        '
 125done
 126
 127test_done