|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +test_description='Test the log command.' |
| 4 | + |
| 5 | +. ./test-lib.sh |
| 6 | + |
| 7 | +test_expect_success 'Attempt log on uninitialized branch' ' |
| 8 | + command_error stg log 2>&1 >/dev/null | grep -e "branch not initialized" |
| 9 | +' |
| 10 | + |
| 11 | +test_expect_success 'Initialize the StGIT repository' ' |
| 12 | + stg init |
| 13 | +' |
| 14 | + |
| 15 | +test_expect_success 'Empty log' ' |
| 16 | + stg log 2>&1 >/dev/null | grep -e "Log is empty" |
| 17 | +' |
| 18 | + |
| 19 | +test_expect_success 'Add some patches' ' |
| 20 | + test_commit p0 file0.txt foo0 && |
| 21 | + test_commit p1 file1.txt foo1 && |
| 22 | + test_commit p2 file2.txt foo2 && |
| 23 | + test_commit p3 file3.txt foo3 && |
| 24 | + stg uncommit -n 4 |
| 25 | +' |
| 26 | + |
| 27 | +test_expect_success 'Test log of all patches' ' |
| 28 | + stg log | head -n 1 | grep -e "uncommit" |
| 29 | +' |
| 30 | + |
| 31 | +test_expect_success 'Test invalid opts with clear' ' |
| 32 | + command_error stg log --diff --clear 2>&1 >/dev/null | |
| 33 | + grep -e "cannot combine --clear with other options" && |
| 34 | + stg log | head -n 1 | grep -e "uncommit" |
| 35 | +' |
| 36 | + |
| 37 | +test_expect_success 'Test invalid args with clear' ' |
| 38 | + command_error stg log --clear p0 p1 2>&1 >/dev/null | |
| 39 | + grep -e "cannot combine --clear with patch arguments" && |
| 40 | + stg log | head -n 1 | grep -e "uncommit" |
| 41 | +' |
| 42 | + |
| 43 | +test_expect_success 'Test invalid opts with graphical' ' |
| 44 | + command_error stg log --graphical -n 5 p0 p1 2>&1 >/dev/null | |
| 45 | + grep -e "cannot combine --graphical and --number" |
| 46 | +' |
| 47 | + |
| 48 | +test_expect_success 'Test log full' ' |
| 49 | + stg log --full > log.txt && |
| 50 | + test_line_count = 5 log.txt && |
| 51 | + head -n 1 log.txt | tail -n 1 | grep -e "commit" |
| 52 | + head -n 2 log.txt | tail -n 1 | grep -e "Author: A Ú Thor" |
| 53 | + head -n 3 log.txt | tail -n 1 | grep -e "Date: " |
| 54 | + head -n 4 log.txt | tail -n 1 | grep -E "^$" |
| 55 | + head -n 5 log.txt | tail -n 1 | grep -E "^ uncommit" |
| 56 | +' |
| 57 | + |
| 58 | +test_expect_success 'Make changes to patches' ' |
| 59 | + stg goto p1 && |
| 60 | + echo "bar1" > file1.txt && |
| 61 | + stg refresh && |
| 62 | + echo "baz1" > file1.txt && |
| 63 | + stg refresh && |
| 64 | + stg goto p2 && |
| 65 | + echo "bar2" > file2.txt && |
| 66 | + stg refresh && |
| 67 | + stg goto p3 && |
| 68 | + stg edit --sign |
| 69 | +' |
| 70 | + |
| 71 | +test_expect_success 'Verify log for p0' ' |
| 72 | + stg log p0 > log.txt && |
| 73 | + test_line_count = 1 log.txt && |
| 74 | + grep -e "uncommit" log.txt |
| 75 | +' |
| 76 | + |
| 77 | +test_expect_success 'Log with diff' ' |
| 78 | + stg log --diff p0 > log.txt && |
| 79 | + grep -e "diff --git a/patches/p0 b/patches/p0" log.txt |
| 80 | +' |
| 81 | + |
| 82 | +test_expect_success 'Verify log for p1' ' |
| 83 | + stg log p1 > log.txt && |
| 84 | + test_line_count = 3 log.txt && |
| 85 | + head -n 1 log.txt | tail -n 1 | grep -e "refresh" && |
| 86 | + head -n 2 log.txt | tail -n 1 | grep -e "refresh" && |
| 87 | + head -n 3 log.txt | tail -n 1 | grep -e "uncommit" |
| 88 | +' |
| 89 | + |
| 90 | +test_expect_success 'Verify log for p2' ' |
| 91 | + stg log p2 > log.txt && |
| 92 | + test_line_count = 3 log.txt && |
| 93 | + head -n 1 log.txt | tail -n 1 | grep -e "refresh" && |
| 94 | + head -n 2 log.txt | tail -n 1 | grep -e "goto" && |
| 95 | + head -n 3 log.txt | tail -n 1 | grep -e "uncommit" |
| 96 | +' |
| 97 | + |
| 98 | +test_expect_success 'Verify log for p3' ' |
| 99 | + stg log p3 > log.txt && |
| 100 | + test_line_count = 3 log.txt && |
| 101 | + head -n 1 log.txt | tail -n 1 | grep -e "edit" && |
| 102 | + head -n 2 log.txt | tail -n 1 | grep -e "goto" && |
| 103 | + head -n 3 log.txt | tail -n 1 | grep -e "uncommit" |
| 104 | +' |
| 105 | + |
| 106 | +test_expect_success 'Verify log for p2 and p3' ' |
| 107 | + stg log p2 p3 > log.txt && |
| 108 | + test_line_count = 5 log.txt && |
| 109 | + head -n 1 log.txt | tail -n 1 | grep -e "edit" && |
| 110 | + head -n 2 log.txt | tail -n 1 | grep -e "goto" && |
| 111 | + head -n 3 log.txt | tail -n 1 | grep -e "refresh" && |
| 112 | + head -n 4 log.txt | tail -n 1 | grep -e "goto" && |
| 113 | + head -n 5 log.txt | tail -n 1 | grep -e "uncommit" |
| 114 | +' |
| 115 | + |
| 116 | +test_expect_success 'Log with number' ' |
| 117 | + stg log -n3 p2 p3 > log.txt && |
| 118 | + test_line_count = 3 log.txt && |
| 119 | + head -n 1 log.txt | tail -n 1 | grep -e "edit" && |
| 120 | + head -n 2 log.txt | tail -n 1 | grep -e "goto" && |
| 121 | + head -n 3 log.txt | tail -n 1 | grep -e "refresh" |
| 122 | +' |
| 123 | + |
| 124 | +test_expect_success 'Clear the log' ' |
| 125 | + stg log --clear && |
| 126 | + test "$(echo $(stg series --noprefix))" = "p0 p1 p2 p3" && |
| 127 | + stg log 2>&1 >/dev/null | grep -e "Log is empty" |
| 128 | +' |
| 129 | + |
| 130 | +test_done |
0 commit comments