t / t1414-reflog-walk.shon commit Fourth batch (bc12974)
   1#!/bin/sh
   2
   3test_description='various tests of reflog walk (log -g) behavior'
   4. ./test-lib.sh
   5
   6test_expect_success 'set up some reflog entries' '
   7        test_commit one &&
   8        test_commit two &&
   9        git checkout -b side HEAD^ &&
  10        test_commit three &&
  11        git merge --no-commit master &&
  12        echo evil-merge-content >>one.t &&
  13        test_tick &&
  14        git commit --no-edit -a
  15'
  16
  17do_walk () {
  18        git log -g --format="%gd %gs" "$@"
  19}
  20
  21test_expect_success 'set up expected reflog' '
  22        cat >expect.all <<-EOF
  23        HEAD@{0} commit (merge): Merge branch ${SQ}master${SQ} into side
  24        HEAD@{1} commit: three
  25        HEAD@{2} checkout: moving from master to side
  26        HEAD@{3} commit: two
  27        HEAD@{4} commit (initial): one
  28        EOF
  29'
  30
  31test_expect_success 'reflog walk shows expected logs' '
  32        do_walk >actual &&
  33        test_cmp expect.all actual
  34'
  35
  36test_expect_success 'reflog can limit with --no-merges' '
  37        grep -v merge expect.all >expect &&
  38        do_walk --no-merges >actual &&
  39        test_cmp expect actual
  40'
  41
  42test_expect_success 'reflog can limit with pathspecs' '
  43        grep two expect.all >expect &&
  44        do_walk -- two.t >actual &&
  45        test_cmp expect actual
  46'
  47
  48test_expect_success 'pathspec limiting handles merges' '
  49        # we pick up:
  50        #   - the initial commit of one
  51        #   - the checkout back to commit one
  52        #   - the evil merge which touched one
  53        sed -n "1p;3p;5p" expect.all >expect &&
  54        do_walk -- one.t >actual &&
  55        test_cmp expect actual
  56'
  57
  58test_expect_success '--parents shows true parents' '
  59        # convert newlines to spaces
  60        echo $(git rev-parse HEAD HEAD^1 HEAD^2) >expect &&
  61        git rev-list -g --parents -1 HEAD >actual &&
  62        test_cmp expect actual
  63'
  64
  65test_expect_success 'walking multiple reflogs shows all' '
  66        # We expect to see all entries for all reflogs, but interleaved by
  67        # date, with order on the command line breaking ties. We
  68        # can use "sort" on the separate lists to generate this,
  69        # but note two tricks:
  70        #
  71        #   1. We use "{" as the delimiter, which lets us skip to the reflog
  72        #      date specifier as our second field, and then our "-n" numeric
  73        #      sort ignores the bits after the timestamp.
  74        #
  75        #   2. POSIX leaves undefined whether this is a stable sort or not. So
  76        #      we use "-k 1" to ensure that we see HEAD before master before
  77        #      side when breaking ties.
  78        {
  79                do_walk --date=unix HEAD &&
  80                do_walk --date=unix side &&
  81                do_walk --date=unix master
  82        } >expect.raw &&
  83        sort -t "{" -k 2nr -k 1 <expect.raw >expect &&
  84        do_walk --date=unix HEAD master side >actual &&
  85        test_cmp expect actual
  86'
  87
  88test_expect_success 'date-limiting does not interfere with other logs' '
  89        do_walk HEAD@{1979-01-01} HEAD >actual &&
  90        test_cmp expect.all actual
  91'
  92
  93test_expect_success 'min/max age uses entry date to limit' '
  94        # Flip between commits one and two so each ref update actually
  95        # does something (and does not get optimized out). We know
  96        # that the timestamps of those commits will be before our "min".
  97
  98        git update-ref -m before refs/heads/minmax one &&
  99
 100        test_tick &&
 101        min=$test_tick &&
 102        git update-ref -m min refs/heads/minmax two &&
 103
 104        test_tick &&
 105        max=$test_tick &&
 106        git update-ref -m max refs/heads/minmax one &&
 107
 108        test_tick &&
 109        git update-ref -m after refs/heads/minmax two &&
 110
 111        cat >expect <<-\EOF &&
 112        max
 113        min
 114        EOF
 115        git log -g --since=$min --until=$max --format=%gs minmax >actual &&
 116        test_cmp expect actual
 117'
 118
 119test_expect_success 'walk prefers reflog to ref tip' '
 120        head=$(git rev-parse HEAD) &&
 121        one=$(git rev-parse one) &&
 122        ident="$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE" &&
 123        echo "$head $one $ident broken reflog entry" >>.git/logs/HEAD &&
 124
 125        echo $one >expect &&
 126        git log -g --format=%H -1 >actual &&
 127        test_cmp expect actual
 128'
 129
 130test_expect_success 'rev-list -g complains when there are no reflogs' '
 131        test_must_fail git rev-list -g
 132'
 133
 134test_done