.github/workflows/main.yml: run static-analysis on bionic
[git/debian.git] / t / t1414-reflog-walk.sh
blob1181a9fb28e359e803ef5672ff7742187e7730f1
1 #!/bin/sh
3 test_description='various tests of reflog walk (log -g) behavior'
4 . ./test-lib.sh
6 test_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
17 do_walk () {
18 git log -g --format="%gd %gs" "$@"
21 test_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
31 test_expect_success 'reflog walk shows expected logs' '
32 do_walk >actual &&
33 test_cmp expect.all actual
36 test_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
42 test_expect_success 'reflog can limit with pathspecs' '
43 grep two expect.all >expect &&
44 do_walk -- two.t >actual &&
45 test_cmp expect actual
48 test_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
58 test_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
65 test_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:
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.
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.
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
88 test_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
93 test_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".
98 git update-ref -m before refs/heads/minmax one &&
100 test_tick &&
101 min=$test_tick &&
102 git update-ref -m min refs/heads/minmax two &&
104 test_tick &&
105 max=$test_tick &&
106 git update-ref -m max refs/heads/minmax one &&
108 test_tick &&
109 git update-ref -m after refs/heads/minmax two &&
111 cat >expect <<-\EOF &&
115 git log -g --since=$min --until=$max --format=%gs minmax >actual &&
116 test_cmp expect actual
119 test_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 &&
125 echo $one >expect &&
126 git log -g --format=%H -1 >actual &&
127 test_cmp expect actual
130 test_expect_success 'rev-list -g complains when there are no reflogs' '
131 test_must_fail git rev-list -g
134 test_done