3 test_description='various tests of reflog walk (log -g) behavior'
6 test_expect_success 'set up some reflog entries' '
9 git checkout -b side HEAD^ &&
11 git merge --no-commit master &&
12 echo evil-merge-content >>one.t &&
14 git commit --no-edit -a
18 git log -g --format="%gd %gs" "$@"
22 test_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
28 HEAD@{4} commit (initial): one
32 test_expect_success 'reflog walk shows expected logs' '
34 test_cmp expect.all actual
37 test_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
43 test_expect_success 'reflog can limit with pathspecs' '
44 grep two expect.all >expect &&
45 do_walk -- two.t >actual &&
46 test_cmp expect actual
49 test_expect_success 'pathspec limiting handles merges' '
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
59 test_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
66 test_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:
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.
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.
80 do_walk --date=unix HEAD &&
81 do_walk --date=unix side &&
82 do_walk --date=unix master
84 sort -t "{" -k 2nr -k 1 <expect.raw >expect &&
85 do_walk --date=unix HEAD master side >actual &&
86 test_cmp expect actual
89 test_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
94 test_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".
99 git update-ref -m before refs/heads/minmax one &&
103 git update-ref -m min refs/heads/minmax two &&
107 git update-ref -m max refs/heads/minmax one &&
110 git update-ref -m after refs/heads/minmax two &&
112 cat >expect <<-\EOF &&
116 git log -g --since=$min --until=$max --format=%gs minmax >actual &&
117 test_cmp expect actual
120 test_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 &&
127 git log -g --format=%H -1 >actual &&
128 test_cmp expect actual
131 test_expect_success 'rev-list -g complains when there are no reflogs' '
132 test_must_fail git rev-list -g