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