Tests redirect to err file when grepping stderr
[stgit.git] / t / t0009-log.sh
blob5fe67ca0b7ff6a9a48a3ab33b814b3de9d1c7e9e
1 #!/bin/sh
3 test_description='Test the log command.'
5 . ./test-lib.sh
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' '
13 stg init
16 test_expect_success 'Empty log' '
17 stg log > log.txt &&
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 &&
27 stg uncommit -n 4
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' '
62 stg goto p1 &&
63 echo "bar1" > file1.txt &&
64 stg refresh &&
65 echo "baz1" > file1.txt &&
66 stg refresh &&
67 stg goto p2 &&
68 echo "bar2" > file2.txt &&
69 stg refresh &&
70 stg goto p3 &&
71 stg edit --sign
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' '
110 mkdir subdir &&
111 (cd subdir &&
112 stg log p3 > ../log.txt
113 ) &&
114 rmdir subdir &&
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' '
140 stg log --clear &&
141 test "$(echo $(stg series --noprefix))" = "p0 p1 p2 p3" &&
142 stg log > log.txt &&
143 test_line_count = 1 log.txt &&
144 head -n 1 log.txt | grep -e "clear log"
147 test_done