Repair import sort in pkgtest.py
[stgit.git] / t / t0009-log.sh
blob8a2e5897df06d6a43073f8ea4eee3b2468d9a08e
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 with patch limit from subdir' '
109 mkdir subdir &&
110 (cd subdir &&
111 stg log p3 > ../log.txt
112 ) &&
113 rmdir subdir &&
114 test_line_count = 3 log.txt &&
115 head -n 1 log.txt | tail -n 1 | grep -e "edit" &&
116 head -n 2 log.txt | tail -n 1 | grep -e "goto" &&
117 head -n 3 log.txt | tail -n 1 | grep -e "uncommit"
120 test_expect_success 'Verify log for p2 and p3' '
121 stg log p2 p3 > log.txt &&
122 test_line_count = 5 log.txt &&
123 head -n 1 log.txt | tail -n 1 | grep -e "edit" &&
124 head -n 2 log.txt | tail -n 1 | grep -e "goto" &&
125 head -n 3 log.txt | tail -n 1 | grep -e "refresh" &&
126 head -n 4 log.txt | tail -n 1 | grep -e "goto" &&
127 head -n 5 log.txt | tail -n 1 | grep -e "uncommit"
130 test_expect_success 'Log with number' '
131 stg log -n3 p2 p3 > log.txt &&
132 test_line_count = 3 log.txt &&
133 head -n 1 log.txt | tail -n 1 | grep -e "edit" &&
134 head -n 2 log.txt | tail -n 1 | grep -e "goto" &&
135 head -n 3 log.txt | tail -n 1 | grep -e "refresh"
138 test_expect_success 'Clear the log' '
139 stg log --clear &&
140 test "$(echo $(stg series --noprefix))" = "p0 p1 p2 p3" &&
141 stg log > log.txt &&
142 test_line_count = 1 log.txt &&
143 head -n 1 log.txt | grep -e "clear log"
146 test_done