Stack state initialization message improvements
[stgit.git] / t / t0009-log.sh
bloba76ab68a1afa65ba89d8ed3583e14315e36b6b60
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>&1 >/dev/null | grep -e "branch not initialized"
11 test_expect_success 'Initialize the StGIT repository' '
12 stg init
15 test_expect_success 'Empty log' '
16 stg log > log.txt &&
17 test_line_count = 1 log.txt &&
18 head -n 1 log.txt | grep -e "initialise"
21 test_expect_success 'Add some patches' '
22 test_commit p0 file0.txt foo0 &&
23 test_commit p1 file1.txt foo1 &&
24 test_commit p2 file2.txt foo2 &&
25 test_commit p3 file3.txt foo3 &&
26 stg uncommit -n 4
29 test_expect_success 'Test log of all patches' '
30 stg log | head -n 1 | grep -e "uncommit"
33 test_expect_success 'Test invalid opts with clear' '
34 command_error stg log --diff --clear 2>&1 >/dev/null |
35 grep -e "cannot combine --clear with other options" &&
36 stg log | head -n 1 | grep -e "uncommit"
39 test_expect_success 'Test invalid args with clear' '
40 command_error stg log --clear p0 p1 2>&1 >/dev/null |
41 grep -e "cannot combine --clear with patch arguments" &&
42 stg log | head -n 1 | grep -e "uncommit"
45 test_expect_success 'Test invalid opts with graphical' '
46 command_error stg log --graphical -n 5 p0 p1 2>&1 >/dev/null |
47 grep -e "cannot combine --graphical and --number"
50 test_expect_success 'Test log full' '
51 stg log --full > log.txt &&
52 test_line_count = 5 log.txt &&
53 head -n 1 log.txt | tail -n 1 | grep -e "commit"
54 head -n 2 log.txt | tail -n 1 | grep -e "Author: A Ú Thor"
55 head -n 3 log.txt | tail -n 1 | grep -e "Date: "
56 head -n 4 log.txt | tail -n 1 | grep -E "^$"
57 head -n 5 log.txt | tail -n 1 | grep -E "^ uncommit"
60 test_expect_success 'Make changes to patches' '
61 stg goto p1 &&
62 echo "bar1" > file1.txt &&
63 stg refresh &&
64 echo "baz1" > file1.txt &&
65 stg refresh &&
66 stg goto p2 &&
67 echo "bar2" > file2.txt &&
68 stg refresh &&
69 stg goto p3 &&
70 stg edit --sign
73 test_expect_success 'Verify log for p0' '
74 stg log p0 > log.txt &&
75 test_line_count = 1 log.txt &&
76 grep -e "uncommit" log.txt
79 test_expect_success 'Log with diff' '
80 stg log --diff p0 > log.txt &&
81 grep -e "diff --git a/patches/p0 b/patches/p0" log.txt
84 test_expect_success 'Verify log for p1' '
85 stg log p1 > log.txt &&
86 test_line_count = 3 log.txt &&
87 head -n 1 log.txt | tail -n 1 | grep -e "refresh" &&
88 head -n 2 log.txt | tail -n 1 | grep -e "refresh" &&
89 head -n 3 log.txt | tail -n 1 | grep -e "uncommit"
92 test_expect_success 'Verify log for p2' '
93 stg log p2 > log.txt &&
94 test_line_count = 3 log.txt &&
95 head -n 1 log.txt | tail -n 1 | grep -e "refresh" &&
96 head -n 2 log.txt | tail -n 1 | grep -e "goto" &&
97 head -n 3 log.txt | tail -n 1 | grep -e "uncommit"
100 test_expect_success 'Verify log for p3' '
101 stg log p3 > log.txt &&
102 test_line_count = 3 log.txt &&
103 head -n 1 log.txt | tail -n 1 | grep -e "edit" &&
104 head -n 2 log.txt | tail -n 1 | grep -e "goto" &&
105 head -n 3 log.txt | tail -n 1 | grep -e "uncommit"
108 test_expect_success 'Verify log for p2 and p3' '
109 stg log p2 p3 > log.txt &&
110 test_line_count = 5 log.txt &&
111 head -n 1 log.txt | tail -n 1 | grep -e "edit" &&
112 head -n 2 log.txt | tail -n 1 | grep -e "goto" &&
113 head -n 3 log.txt | tail -n 1 | grep -e "refresh" &&
114 head -n 4 log.txt | tail -n 1 | grep -e "goto" &&
115 head -n 5 log.txt | tail -n 1 | grep -e "uncommit"
118 test_expect_success 'Log with number' '
119 stg log -n3 p2 p3 > log.txt &&
120 test_line_count = 3 log.txt &&
121 head -n 1 log.txt | tail -n 1 | grep -e "edit" &&
122 head -n 2 log.txt | tail -n 1 | grep -e "goto" &&
123 head -n 3 log.txt | tail -n 1 | grep -e "refresh"
126 test_expect_success 'Clear the log' '
127 stg log --clear &&
128 test "$(echo $(stg series --noprefix))" = "p0 p1 p2 p3" &&
129 stg log > log.txt &&
130 test_line_count = 1 log.txt &&
131 head -n 1 log.txt | grep -e "clear log"
134 test_done