]> git.ipfire.org Git - thirdparty/git.git/blame - t/t1414-reflog-walk.sh
get_revision_1(): replace do-while with an early return
[thirdparty/git.git] / t / t1414-reflog-walk.sh
CommitLineData
7cf686b9
JK
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_failure '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_failure '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_failure '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_failure '--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_failure '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_failure 'walk prefers reflog to ref tip' '
95 head=$(git rev-parse HEAD) &&
96 one=$(git rev-parse one) &&
97 ident="$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE" &&
98 echo "$head $one $ident broken reflog entry" >>.git/logs/HEAD &&
99
100 echo $one >expect &&
101 git log -g --format=%H -1 >actual &&
102 test_cmp expect actual
103'
104
105test_done