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 'Invalid patch name: trailing periods in shortened name' '
47 test_config stgit.namelength 10 &&
48 stg new -m "aaa. bbb. ccc." &&
49 test "$(echo $(stg top))" = "aaa-bbb" &&
54 'Create a patch without giving a name' '
56 [ "$(echo $(stg top))" = "yo" ] &&
57 [ $(stg series --applied -c) -eq 2 ]
61 'Attempt to create patch with duplicate name' '
62 command_error stg new foo -m "duplicate foo" 2>&1 |
63 grep -e "foo: patch already exists"
67 'Attempt new with conflicts' '
69 echo "something" > file.txt &&
73 echo "something else" > file.txt &&
77 echo "something different" > file.txt &&
79 conflict stg push p1 &&
80 command_error stg new -m p3 2>&1 |
81 grep -e "Cannot create a new patch -- resolve conflicts first" &&
87 stg new --save-template new-tmpl.txt &&
88 test_path_is_file new-tmpl.txt
92 'New with patchdescr.tmpl' '
93 echo "Patch Description Template" > .git/patchdescr.tmpl &&
94 stg new templated-patch &&
95 stg show | grep "Patch Description Template"
98 test_expect_success
'Setup fake editor' '
99 write_script fake-editor <<-\EOF
100 cat "$1" > raw_commit_message.txt
103 test_expect_success \
104 'New without verbose flag' '
105 test_set_editor "$(pwd)/fake-editor" &&
106 test_when_finished test_set_editor false &&
107 echo "something else" > file.txt &&
108 stg new no-verbose-patch &&
109 test_must_fail grep "something else" raw_commit_message.txt
112 test_expect_success \
113 'New with verbose flag' '
114 test_set_editor "$(pwd)/fake-editor" &&
115 test_when_finished test_set_editor false &&
116 stg new --verbose verbose-flag-patch &&
117 stg show | grep "Patch Description Template" &&
118 grep "something else" raw_commit_message.txt
121 test_expect_success \
122 'New with verbose config option' '
123 test_set_editor "$(pwd)/fake-editor" &&
124 test_when_finished test_set_editor false &&
125 test_config stgit.new.verbose "1" &&
126 stg new verbose-config-patch &&
127 grep "something else" raw_commit_message.txt
130 test_expect_success \
131 'New with verbose config boolean option' '
132 test_set_editor "$(pwd)/fake-editor" &&
133 test_when_finished test_set_editor false &&
134 test_config stgit.new.verbose "true" &&
135 stg new verbose-config-bool-patch &&
136 grep "something else" raw_commit_message.txt
139 test_expect_success \
140 'Use stgit.autosign' '
141 test_config stgit.autosign "Signed-off-by" &&
142 stg new -m autosigned-patch &&
143 git cat-file -p HEAD | grep -e "Signed-off-by: C Ó Mitter <committer@example.com>"
146 test_expect_failure \
147 'Patch with slash in name' '
148 stg new bar/foo -m "patch bar/foo"