3 # Copyright (c) 2007 Karl Hasselström
6 test_description
='Test "stg new".'
11 'Initialize the StGit repository' '
16 'Too many arguments' '
17 command_error stg new foo extra_arg 2>&1 |
18 grep -e "incorrect number of arguments"
22 'Create a named patch' '
23 stg new foo -m foobar &&
24 [ $(stg series --applied -c) -eq 1 ]
28 'Invalid patch name: space' '
29 command_error stg new "bad name" 2>&1 >/dev/null |
30 grep -e "Invalid patch name: \"bad name\""
34 'Invalid patch name: carat' '
35 command_error stg new "bad^name" 2>&1 >/dev/null |
36 grep -e "Invalid patch name: \"bad\^name\""
40 'Invalid patch name: empty' '
41 command_error stg new "" 2>&1 >/dev/null |
42 grep -e "Invalid patch name: \"\""
46 'Create a patch without giving a name' '
48 [ "$(echo $(stg top))" = "yo" ] &&
49 [ $(stg series --applied -c) -eq 2 ]
53 'Attempt to create patch with duplicate name' '
54 command_error stg new foo -m "duplicate foo" 2>&1 |
55 grep -e "foo: patch already exists"
59 'Attempt new with conflicts' '
61 echo "something" > file.txt &&
65 echo "something else" > file.txt &&
69 echo "something different" > file.txt &&
71 conflict stg push p1 &&
72 command_error stg new -m p3 2>&1 |
73 grep -e "Cannot create a new patch -- resolve conflicts first" &&
79 stg new --save-template new-tmpl.txt &&
80 test_path_is_file new-tmpl.txt
84 'New with patchdescr.tmpl' '
85 echo "Patch Description Template" > .git/patchdescr.tmpl &&
86 stg new templated-patch &&
87 stg show | grep "Patch Description Template"
90 test_expect_success
'Setup fake editor' '
91 write_script fake-editor <<-\EOF
92 cat "$1" > raw_commit_message.txt
96 'New without verbose flag' '
97 test_set_editor "$(pwd)/fake-editor" &&
98 test_when_finished test_set_editor false &&
99 echo "something else" > file.txt &&
100 stg new no-verbose-patch &&
101 test_must_fail grep "something else" raw_commit_message.txt
104 test_expect_success \
105 'New with verbose flag' '
106 test_set_editor "$(pwd)/fake-editor" &&
107 test_when_finished test_set_editor false &&
108 stg new --verbose verbose-flag-patch &&
109 stg show | grep "Patch Description Template" &&
110 grep "something else" raw_commit_message.txt
113 test_expect_success \
114 'New with verbose config option' '
115 test_set_editor "$(pwd)/fake-editor" &&
116 test_when_finished test_set_editor false &&
117 test_config commit.verbose "1" &&
118 stg new verbose-config-patch &&
119 grep "something else" raw_commit_message.txt
122 test_expect_success \
123 'New with verbose config boolean option' '
124 test_set_editor "$(pwd)/fake-editor" &&
125 test_when_finished test_set_editor false &&
126 test_config commit.verbose "true" &&
127 stg new verbose-config-bool-patch &&
128 grep "something else" raw_commit_message.txt
131 test_expect_failure \
132 'Patch with slash in name' '
133 stg new bar/foo -m "patch bar/foo"