3 # Copyright (c) 2006 Ilpo Järvinen
6 test_description
='Test "stg goto"'
10 test_expect_success
'Initialize stgit repository' '
12 for i in 1 2 3 4 5; do
13 stg new p$i -m "patch $i" &&
20 test_expect_success
'Test invalid number of arguments' '
21 command_error stg goto 2>err &&
22 grep -e "incorrect number of arguments" err
25 test_expect_success
'Goto current patch' '
26 stg goto $(stg top) &&
27 test "$(echo $(stg top))" = "p5"
30 test_expect_success
'Attempt goto invalid patch' '
31 command_error stg goto p999 2>err &&
32 grep -e "Patch \"p999\" does not exist" err
35 test_expect_success
'Attempt goto invalid hash' '
36 command_error stg goto beeff00d 2>err &&
37 grep -e "No patch associated with beeff00d" err
40 test_expect_success
'Goto a patch' '
42 test "$(echo $(stg series --applied --noprefix))" = "p1 p2 p3" &&
43 test "$(echo $(stg series --unapplied --noprefix))" = "p4 p5"
46 test_expect_success
'Goto by partial sha1' '
47 stg goto "$(echo $(stg id p5) | test_copy_bytes 10)" &&
48 test "$(echo $(stg series --applied --noprefix))" = "p1 p2 p3 p4 p5" &&
49 stg goto "$(echo $(stg id p3))" &&
50 test "$(echo $(stg series --applied --noprefix))" = "p1 p2 p3" &&
51 test "$(echo $(stg series --unapplied --noprefix))" = "p4 p5"
54 test_expect_success
'Refuse to go to a hidden patch' '
55 stg new h0 -m "hidden patch" &&
57 command_error stg goto h0 2>err &&
58 grep -e "Cannot goto a hidden patch" err &&
59 test "$(echo $(stg series --hidden --noprefix))" = "h0" &&
60 test "$(echo $(stg series --applied --noprefix))" = "p1 p2 p3" &&
61 test "$(echo $(stg series --unapplied --noprefix))" = "p4 p5"
64 test_expect_success
'Goto with merge check' '
65 stg goto --merged p5 &&
66 test "$(echo $(stg series --applied --noprefix))" = "p1 p2 p3 p4 p5" &&
67 test "$(echo $(stg series --unapplied --noprefix))" = ""
70 test_expect_success
'Goto with ambiguous patch substring' '
72 command_error stg goto p 2>err &&
73 grep "Ambiguous patch name \"p\"" err