3 test_description
='Test the log command.'
7 test_expect_success
'Attempt log on uninitialized branch' '
8 command_error stg log 2>err >/dev/null &&
9 grep -e "branch not initialized" err
12 test_expect_success
'Initialize the StGit repository' '
16 test_expect_success
'Empty log' '
18 test_line_count = 1 log.txt &&
19 head -n 1 log.txt | grep -e "initialise"
22 test_expect_success
'Add some patches' '
23 test_commit p0 file0.txt foo0 &&
24 test_commit p1 file1.txt foo1 &&
25 test_commit p2 file2.txt foo2 &&
26 test_commit p3 file3.txt foo3 &&
30 test_expect_success
'Test log of all patches' '
31 stg log | head -n 1 | grep -e "uncommit"
34 test_expect_success
'Test invalid opts with clear' '
35 command_error stg log --diff --clear 2>err >/dev/null &&
36 grep -e "cannot combine --clear with other options" err &&
37 stg log | head -n 1 | grep -e "uncommit"
40 test_expect_success
'Test invalid args with clear' '
41 command_error stg log --clear p0 p1 2>err >/dev/null &&
42 grep -e "cannot combine --clear with patch arguments" err &&
43 stg log | head -n 1 | grep -e "uncommit"
46 test_expect_success
'Test invalid opts with graphical' '
47 command_error stg log --graphical -n 5 p0 p1 2>err >/dev/null &&
48 grep -e "cannot combine --graphical and --number" err
51 test_expect_success
'Test log full' '
52 stg log --full > log.txt &&
53 test_line_count = 5 log.txt &&
54 head -n 1 log.txt | tail -n 1 | grep -e "commit"
55 head -n 2 log.txt | tail -n 1 | grep -e "Author: A Ú Thor"
56 head -n 3 log.txt | tail -n 1 | grep -e "Date: "
57 head -n 4 log.txt | tail -n 1 | grep -E "^$"
58 head -n 5 log.txt | tail -n 1 | grep -E "^ uncommit"
61 test_expect_success
'Make changes to patches' '
63 echo "bar1" > file1.txt &&
65 echo "baz1" > file1.txt &&
68 echo "bar2" > file2.txt &&
74 test_expect_success
'Verify log for p0' '
75 stg log p0 > log.txt &&
76 test_line_count = 1 log.txt &&
77 grep -e "uncommit" log.txt
80 test_expect_success
'Log with diff' '
81 stg log --diff p0 > log.txt &&
82 grep -e "diff --git a/patches/p0 b/patches/p0" log.txt
85 test_expect_success
'Verify log for p1' '
86 stg log p1 > log.txt &&
87 test_line_count = 3 log.txt &&
88 head -n 1 log.txt | tail -n 1 | grep -e "refresh" &&
89 head -n 2 log.txt | tail -n 1 | grep -e "refresh" &&
90 head -n 3 log.txt | tail -n 1 | grep -e "uncommit"
93 test_expect_success
'Verify log for p2' '
94 stg log p2 > log.txt &&
95 test_line_count = 3 log.txt &&
96 head -n 1 log.txt | tail -n 1 | grep -e "refresh" &&
97 head -n 2 log.txt | tail -n 1 | grep -e "goto" &&
98 head -n 3 log.txt | tail -n 1 | grep -e "uncommit"
101 test_expect_success
'Verify log for p3' '
102 stg log p3 > log.txt &&
103 test_line_count = 3 log.txt &&
104 head -n 1 log.txt | tail -n 1 | grep -e "edit" &&
105 head -n 2 log.txt | tail -n 1 | grep -e "goto" &&
106 head -n 3 log.txt | tail -n 1 | grep -e "uncommit"
109 test_expect_success
'Verify log with patch limit from subdir' '
112 stg log p3 > ../log.txt
115 test_line_count = 3 log.txt &&
116 head -n 1 log.txt | tail -n 1 | grep -e "edit" &&
117 head -n 2 log.txt | tail -n 1 | grep -e "goto" &&
118 head -n 3 log.txt | tail -n 1 | grep -e "uncommit"
121 test_expect_success
'Verify log for p2 and p3' '
122 stg log p2 p3 > log.txt &&
123 test_line_count = 5 log.txt &&
124 head -n 1 log.txt | tail -n 1 | grep -e "edit" &&
125 head -n 2 log.txt | tail -n 1 | grep -e "goto" &&
126 head -n 3 log.txt | tail -n 1 | grep -e "refresh" &&
127 head -n 4 log.txt | tail -n 1 | grep -e "goto" &&
128 head -n 5 log.txt | tail -n 1 | grep -e "uncommit"
131 test_expect_success
'Log with number' '
132 stg log -n3 p2 p3 > log.txt &&
133 test_line_count = 3 log.txt &&
134 head -n 1 log.txt | tail -n 1 | grep -e "edit" &&
135 head -n 2 log.txt | tail -n 1 | grep -e "goto" &&
136 head -n 3 log.txt | tail -n 1 | grep -e "refresh"
139 test_expect_success
'Clear the log' '
141 test "$(echo $(stg series --noprefix))" = "p0 p1 p2 p3" &&
143 test_line_count = 1 log.txt &&
144 head -n 1 log.txt | grep -e "clear log"