Restore `stg sink --nopush` capability
[stgit.git] / t / t1003-new.sh
blobd8bae5fd0d74c21539d664bd79b3dd82afccfef1
1 #!/bin/sh
3 # Copyright (c) 2007 Karl Hasselström
6 test_description='Test "stg new".'
8 . ./test-lib.sh
10 test_expect_success \
11 'Initialize the StGit repository' '
12 stg init
15 test_expect_success \
16 'Too many arguments' '
17 command_error stg new foo extra_arg 2>&1 |
18 grep -e "incorrect number of arguments"
21 test_expect_success \
22 'Create a named patch' '
23 stg new foo -m foobar &&
24 [ $(stg series --applied -c) -eq 1 ]
27 test_expect_success \
28 'Invalid patch name: space' '
29 command_error stg new "bad name" 2>&1 >/dev/null |
30 grep -e "Invalid patch name: \"bad name\""
33 test_expect_success \
34 'Invalid patch name: carat' '
35 command_error stg new "bad^name" 2>&1 >/dev/null |
36 grep -e "Invalid patch name: \"bad\^name\""
39 test_expect_success \
40 'Invalid patch name: empty' '
41 command_error stg new "" 2>&1 >/dev/null |
42 grep -e "Invalid patch name: \"\""
45 test_expect_success \
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" &&
50 stg delete --top
53 test_expect_success \
54 'Create a patch without giving a name' '
55 stg new -m yo &&
56 [ "$(echo $(stg top))" = "yo" ] &&
57 [ $(stg series --applied -c) -eq 2 ]
60 test_expect_success \
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"
66 test_expect_success \
67 'Attempt new with conflicts' '
68 stg new -m p0 &&
69 echo "something" > file.txt &&
70 stg add file.txt &&
71 stg refresh &&
72 stg new -m p1 &&
73 echo "something else" > file.txt &&
74 stg refresh &&
75 stg pop &&
76 stg new -m p2 &&
77 echo "something different" > file.txt &&
78 stg refresh &&
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" &&
82 stg reset --hard
85 test_expect_success \
86 'Save template' '
87 stg new --save-template new-tmpl.txt &&
88 test_path_is_file new-tmpl.txt
91 test_expect_success \
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"
151 test_done